ClassCastException with findFragmentById

I am trying to get a specific fragment with:

RohwareFragmentMatlist fragment = (RohwareFragmentMatlist)getFragmentManager().findFragmentById(R.id.lagerfragment); 

But I get an error message from eclipse with this message:

Cannot be dropped from fragment in RohwareFragmentMatlist

Activity starts with:

 public class RohwareActionBar extends FragmentActivity {... 

RohwareFragmentMatlist is defined as follows:

 public class RohwareFragmentMatlist extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{... 

A fragment is defined as follows:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:name="de.ypssoft.RohwareFragmentMatlist" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" android:id="@+id/lagerfragment" android:layout_margin="5dip" android:layout_marginLeft="10dip" > </fragment> <FrameLayout android:id="@+id/details" android:layout_weight="3" android:layout_width="0px" android:layout_height="match_parent" android:background="?android:attr/detailsElementBackground" /> </LinearLayout> 

Does it work to get the fragment through "getFragmentById" using ListFragment?

+7
source share
1 answer

I found a solution here . Since I am using v4 compatibility pack, I have to use

RohwareFragmentMatlist fragment = (RohwareFragmentMatlist) getSupportFragmentManager (). findFragmentById (R.id.lagerfragment);

instead

RohwareFragmentMatlist fragment = (RohwareFragmentMatlist) getFragmentManager (). findFragmentById (R.id.lagerfragment);

+33
source

All Articles