android - Replace or create a new view within a Fragment? -
i built activity takes data rss file , shows them on listfragment; how defined on layout file:
<fragment android:id="@+id/news_list_fragment" android:name="com.thecoffeedrinker.theforcereader.newslistfragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/header_layout" /> it might happen there no connection available; case want application show layout warn user it, shown in same layout area of list. what's best thing achieve this? should create "disconnected fragment" class , replace instance list on same activity? should load layout within list fragment class? tried replace when resume activity crashes...why that? replies.
to replace 1 fragment another
fragment newfragment = new examplefragment(); fragmenttransaction transaction = getfragmentmanager().begintransaction(); // replace whatever in fragment_container view fragment, // , add transaction stack transaction.replace(r.id.fragment_container, newfragment); transaction.addtobackstack(null); // commit transaction transaction.commit(); adding new fragment
examplefragment fragment = new examplefragment(); fragmenttransaction.add(r.id.fragment_container, fragment); fragmenttransaction.commit();
Comments
Post a Comment