0

I need to get a fragment (ListFragment), but the code below returns null. Edit: I should add that I'm using a ViewPager together with FragmentStatePagerAdapter.

TaskListFragment tlf = (TaskListFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_task_list);

I'm guessing this is because the id is the id of the RelativeLayout in the XML file that makes up the Fragment.

I found a "Fragment" tag, figuring that should enable me to give the fragment an id, but including that tag in the XML file gives me a "Error inflating class fragment" error, even when eclipse shows the XML is valid.

What do I do? Is the problem that the id is wrong? If so, how do I give the fragment an id that can be retrieved using findFragmentById??

Edit: XML added

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

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<TextView
    android:id="@android:id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="no data" />

</RelativeLayout>
abc32112
  • 2,457
  • 9
  • 37
  • 53

0 Answers0