I try to get a specific Fragment with:
RohwareFragmentMatlist fragment = (RohwareFragmentMatlist)getFragmentManager().findFragmentById(R.id.lagerfragment);
But I get an error from eclipse with this message:
Cannot cast from Fragment to RohwareFragmentMatlist
The Activity starts with:
public class RohwareActionBar extends FragmentActivity {...
The RohwareFragmentMatlist is defined as follows:
public class RohwareFragmentMatlist extends ListFragment
implements LoaderManager.LoaderCallbacks<Cursor>{...
The Fragment is defined this way:
<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>
Doesn't it work to get a Fragment via "getFragmentById" using ListFragment?
I found the solution here . Since I'm using compatibility package v4 I have to use
RohwareFragmentMatlist fragment = (RohwareFragmentMatlist)getSupportFragmentManager().findFragmentById(R.id.lagerfragment);
instead of
RohwareFragmentMatlist fragment = (RohwareFragmentMatlist)getFragmentManager().findFragmentById(R.id.lagerfragment);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With