无法在片段中填充ListView

时间:2015-04-11 01:08:26

标签: java android xml listview android-fragments

我正在将对象从MainActivity传递给GradeListActivity。在GradeListActivity我有Fragment(其中包含ListView)。我正在尝试填充此ListView,但每当我的应用运行时,GradListActivity都是空白的。

我调试了我的程序以确保将对象传递给GradeListActivityListViewfragment(片段类),并且它确实被传入。我想我可能没有填充列出正确的地方,但任何帮助或指导将不胜感激。

我的MainActivity.java:

public class MainActivity extends Activity 
{
    public GradeCollection gc;  
    RatingBar GradeRatingBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        GradeRatingBar = (RatingBar) findViewById(R.id.ratingBar);

        gc = new GradeCollection();
        GradeData gd = new GradeData("Exam", 1, 85, "First Exam");
        GradeData gd2 = new GradeData("Homework", 1, 100, "Schedule");
        GradeData gd3 = new GradeData("Homework", 2, 100, "Hello goodbye");
        GradeData gd4= new GradeData("Quiz", 1, 0, "Syllabus");
        GradeData gd5 = new GradeData("Quiz", 2, 80, "Chapter 1");
        GradeData gd6 = new GradeData("Quiz", 3, 60, "Chapter 4");
        GradeData gd7 = new GradeData("Lab", 1, 100, "Hello yankees");
        GradeData gd8 = new GradeData("Lab", 2, 100, "Manifest and Different Screens");
        GradeData gd9 = new GradeData("Lab", 3, 100, "Internalization");
        GradeData gd10 = new GradeData("Lab", 4, 100, "Layout and Controls");
        GradeData gd11 = new GradeData("Lab", 5, 100, "Easy Fragment");
        GradeData gd12 = new GradeData("Lab", 6, 100, "Fragment");
        GradeData gd13 = new GradeData("Lab", 7, 100, "Array Adapters");
        GradeData gd14 = new GradeData("Lab", 8, 100, "Handle Implicit Intents");

        gc.AddGrade(gd);
        gc.AddGrade(gd2);
        gc.AddGrade(gd3);
        gc.AddGrade(gd4);
        gc.AddGrade(gd5);
        gc.AddGrade(gd6);
        gc.AddGrade(gd7);
        gc.AddGrade(gd8);
        gc.AddGrade(gd9);
        gc.AddGrade(gd10);
        gc.AddGrade(gd11);
        gc.AddGrade(gd12);
        gc.AddGrade(gd13);
        gc.AddGrade(gd14);

        double numberGrade = gc.CalcGrade();
        String letterGrade = null;

        if (numberGrade >= 93)
        {
            letterGrade = "A";
        }
        else if (numberGrade >= 90 && numberGrade <= 92)
        {
            letterGrade = "A-";
        }
        else if (numberGrade >= 87 && numberGrade <= 89)
        {
            letterGrade = "B+";
        }
        else if (numberGrade >= 83 && numberGrade <= 86)
        {
            letterGrade = "B";
        }
        else if (numberGrade >= 80 && numberGrade <= 82)
        {
            letterGrade = "B-";
        }
        else if (numberGrade >= 77 && numberGrade <= 79)
        {
            letterGrade = "C+";
        }
        else if (numberGrade >= 73 && numberGrade <= 76)
        {
            letterGrade = "C";
        }
        else if (numberGrade >= 70 && numberGrade <= 72)
        {
            letterGrade = "C-";
        }
        else if (numberGrade >= 67 && numberGrade <= 69)
        {
            letterGrade = "D+";
        }
        else if (numberGrade >= 60 && numberGrade <= 66)
        {
            letterGrade = "D";
        }
        else
        {
            letterGrade = "F";
        }

        TextView textView = (TextView) findViewById(R.id.textViewNumericGrade);
        textView.setText(String.valueOf(numberGrade));

        TextView textView2 = (TextView) findViewById(R.id.textViewLetterGrade);
        textView2.setText(letterGrade);

        if(letterGrade == "A" || letterGrade == "A-")
        {
            GradeRatingBar.setRating(4);
        }
        if (letterGrade == "B+" || letterGrade == "B" || letterGrade == "B-")
        {
            GradeRatingBar.setRating(3);
        }
        if (letterGrade == "C+" || letterGrade == "C" || letterGrade == "C-")
        {
            GradeRatingBar.setRating(2);
        }
        if (letterGrade == "D+" || letterGrade == "D")
        {
            GradeRatingBar.setRating(1);
        }
        if (letterGrade == "F")
        {
            GradeRatingBar.setRating(0);
        }

        Button viewGrades = (Button)findViewById(R.id.buttonViewGrade);
        viewGrades.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v)
        {
            Intent intent = new Intent(MainActivity.this, GradeListActivity.class);
            intent.putExtra("OriginalGradeCollectionInstance", gc);

            startActivity(intent);
        }
           });

    }
}

我的GradeListActivity.java:

public class GradeListActivity extends Activity
{
    public GradeCollection gc = new GradeCollection();

    //private ArrayAdapter<String> namesArrayAdapter;
    //ListView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grade_list_activity);

        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ListViewFragment LVF = new ListViewFragment();
        ft.add(R.id.ui_container, LVF);
        ft.commit();


    }


}

我的ListViewFragment.java:

public class ListViewFragment extends Fragment{

    public GradeCollection gc = new GradeCollection();
    public ArrayList<String> gcCategoryList;
    public ArrayAdapter<String> gcArrayAdapter;

    @Override
    public View onCreateView(   LayoutInflater inflater,
        ViewGroup container,
        Bundle savedInstanceState) 
    {   

        View v = inflater.inflate(R.layout.list_view_fragment, container, false);



        Activity a = getActivity();

        Intent i = a.getIntent();

        gc = (GradeCollection) i.getExtras().getSerializable("OriginalGradeCollectionInstance");
        gcCategoryList = gc.GetCategoryArrayList();

        gcArrayAdapter = new ArrayAdapter<String>(a, R.layout.list_view_fragment, gcCategoryList);

        //lv = (ListView) a.findViewById(R.id.listViewPortrait);

        ListView lv = (ListView) v.findViewById(R.id.listViewPortrait);

        lv.setAdapter(gcArrayAdapter);

        return inflater.inflate(R.layout.list_view_fragment, container, false);

    }

}

我的grade_list_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


     <FrameLayout
        android:id="@+id/ui_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    />

</LinearLayout>

我的list_view_fragment.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listViewPortrait"
        android:layout_width="match_parent"
        android:layout_height="228dp" >
    </ListView>

</LinearLayout>

我的logcat:

04-11 02:35:32.135: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-11 02:35:32.275: E/Trace(836): error opening trace file: No such file or directory (2)
04-11 02:35:32.895: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-11 02:35:36.415: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-11 02:35:36.445: E/ArrayAdapter(836): You must supply a resource ID for a TextView
04-11 02:35:36.555: E/AndroidRuntime(836): FATAL EXCEPTION: main
04-11 02:35:36.555: E/AndroidRuntime(836): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.AbsListView.obtainView(AbsListView.java:2159)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ListView.makeAndAddView(ListView.java:1831)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ListView.fillDown(ListView.java:674)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ListView.fillFromTop(ListView.java:735)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ListView.layoutChildren(ListView.java:1652)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.AbsListView.onLayout(AbsListView.java:1994)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.View.layout(View.java:14008)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.Choreographer.doFrame(Choreographer.java:532)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.os.Handler.handleCallback(Handler.java:725)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.os.Looper.loop(Looper.java:137)
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.app.ActivityThread.main(ActivityThread.java:5041)
04-11 02:35:36.555: E/AndroidRuntime(836):  at java.lang.reflect.Method.invokeNative(Native Method)
04-11 02:35:36.555: E/AndroidRuntime(836):  at java.lang.reflect.Method.invoke(Method.java:511)
04-11 02:35:36.555: E/AndroidRuntime(836):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-11 02:35:36.555: E/AndroidRuntime(836):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-11 02:35:36.555: E/AndroidRuntime(836):  at dalvik.system.NativeStart.main(Native Method)
04-11 02:35:36.555: E/AndroidRuntime(836): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
04-11 02:35:36.555: E/AndroidRuntime(836):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
04-11 02:35:36.555: E/AndroidRuntime(836):  ... 50 more
04-11 02:35:37.066: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-11 02:35:37.495: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
04-11 02:36:08.985: E/ActivityThread(592): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd6e78 that was originally bound here
04-11 02:36:08.985: E/ActivityThread(592): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd6e78 that was originally bound here
04-11 02:36:08.985: E/ActivityThread(592):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-11 02:36:08.985: E/ActivityThread(592):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-11 02:36:08.985: E/ActivityThread(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-11 02:36:08.985: E/ActivityThread(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-11 02:36:08.985: E/ActivityThread(592):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-11 02:36:08.985: E/ActivityThread(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-11 02:36:08.985: E/ActivityThread(592):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 02:36:08.985: E/ActivityThread(592):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 02:36:08.985: E/ActivityThread(592):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 02:36:08.985: E/ActivityThread(592):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 02:36:08.985: E/ActivityThread(592):  at java.lang.Thread.run(Thread.java:856)
04-11 02:36:08.985: E/StrictMode(592): null
04-11 02:36:08.985: E/StrictMode(592): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd6e78 that was originally bound here
04-11 02:36:08.985: E/StrictMode(592):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-11 02:36:08.985: E/StrictMode(592):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-11 02:36:08.985: E/StrictMode(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-11 02:36:08.985: E/StrictMode(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-11 02:36:08.985: E/StrictMode(592):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-11 02:36:08.985: E/StrictMode(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-11 02:36:08.985: E/StrictMode(592):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 02:36:08.985: E/StrictMode(592):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 02:36:08.985: E/StrictMode(592):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 02:36:08.985: E/StrictMode(592):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 02:36:08.985: E/StrictMode(592):  at java.lang.Thread.run(Thread.java:856)
04-11 02:36:09.015: E/ActivityThread(592): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d42588 that was originally bound here
04-11 02:36:09.015: E/ActivityThread(592): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d42588 that was originally bound here
04-11 02:36:09.015: E/ActivityThread(592):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-11 02:36:09.015: E/ActivityThread(592):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-11 02:36:09.015: E/ActivityThread(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-11 02:36:09.015: E/ActivityThread(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-11 02:36:09.015: E/ActivityThread(592):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-11 02:36:09.015: E/ActivityThread(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-11 02:36:09.015: E/ActivityThread(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-11 02:36:09.015: E/ActivityThread(592):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-11 02:36:09.015: E/ActivityThread(592):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-11 02:36:09.015: E/ActivityThread(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-11 02:36:09.015: E/ActivityThread(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-11 02:36:09.015: E/ActivityThread(592):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 02:36:09.015: E/ActivityThread(592):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 02:36:09.015: E/ActivityThread(592):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 02:36:09.015: E/ActivityThread(592):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 02:36:09.015: E/ActivityThread(592):  at java.lang.Thread.run(Thread.java:856)
04-11 02:36:09.025: E/StrictMode(592): null
04-11 02:36:09.025: E/StrictMode(592): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d42588 that was originally bound here
04-11 02:36:09.025: E/StrictMode(592):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-11 02:36:09.025: E/StrictMode(592):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-11 02:36:09.025: E/StrictMode(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-11 02:36:09.025: E/StrictMode(592):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-11 02:36:09.025: E/StrictMode(592):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-11 02:36:09.025: E/StrictMode(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-11 02:36:09.025: E/StrictMode(592):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-11 02:36:09.025: E/StrictMode(592):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-11 02:36:09.025: E/StrictMode(592):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-11 02:36:09.025: E/StrictMode(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-11 02:36:09.025: E/StrictMode(592):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-11 02:36:09.025: E/StrictMode(592):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 02:36:09.025: E/StrictMode(592):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 02:36:09.025: E/StrictMode(592):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 02:36:09.025: E/StrictMode(592):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 02:36:09.025: E/StrictMode(592):  at java.lang.Thread.run(Thread.java:856)

2 个答案:

答案 0 :(得分:1)

检查先生;在onCreateView的{​​{1}};首先,您将Listfragment充气并将其附加到View

v

然后您创建View v = inflater.inflate(R.layout.list_view_fragment, container, false); 并为其设置适配器。所以ListView是填充的v 但是的容器,最后当您将ListView lv发送到您称之为

的片段时
View

膨胀一个可能为空的新 return inflater.inflate(R.layout.list_view_fragment, container, false); ..您的解决方案用View替换该行代码

答案 1 :(得分:0)

在您的片段onCreateView中,您需要重新定义布局并返回新视图。这个新观点对lv没有任何想法 的解决方案:
返回v而不是inflater.inflate(R.layout.list_view_fragment, container, false);