android - Can't get parent view from fragment -
i need update textview listfragment on same plane in xml file textview. both trys returns null:
@override public void oncreate(bundle ice) { super.oncreate(ice); ... madapter = new simplecursoradapter(getactivity(), r.layout.entry_row, null, from, to, 0); setlistadapter(madapter); mtextview = (textview) getactivity().findviewbyid(r.id.tv); // try #1 mpercentview = (textview) ((viewgroup)getview().getparent()).findviewbyid(r.id.tv); //try #2 // (not tested @ same time) }
this xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <textview android:id="@+id/info_log_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:padding="@dimen/object_padding" android:textsize="24sp" android:textisselectable="true" /> <fragment android:id="@+id/view_log_fragment" android:name="fragment name..." android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/info_log_view" /> </relativelayout>
thanks!
this solved problem hope helps too: override class onactivitycreated , in write code below:
view myactivityview=(relativelayout)getactivity().findviewbyid(r.id.parentcontainer);
note relativelayout main layout containing textview. when have in fragment have access fragment parent view , need text view code below:
textview mytextview=(textview)myactivityview.findviewbyid(r.id.mytextview);
hope help.
Comments
Post a Comment