android - Set TextView not changing -
in following code, have options menu , when select menu option, want update textview. setting text works fine , no errors generated. here code settext isn't working. have put in debug statements , code getting hit, text not updating. put arrows next code isn't updating. review other textview examples, can't figure out.
@override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.menu_item_bflat: if (verbose) log.v(tag, "+++ menu_item_bflat +++"); // bflat = 1 mkeyselected = bflat; >>>> mchapterselected.settext("b flat"); return true; case r.id.menu_item_eflat: // eflat = 2 mkeyselected = eflat; >>>> mchapterselected.settext("e flat"); return true; default: return super.onoptionsitemselected(item); } // switch } // onoptionsitemselected here rest of code, if needed:
public class chapterlistfragment extends listfragment { private static final boolean verbose = true; private arraylist<chapters> mchapters; private static final string tag = "chapterlistfragment"; private static final int bflat = 1; private static final int eflat = 2; private textview mchapterselected; private view mview; private int mkeyselected; @override public void oncreate(bundle savedinstancestate) { if (verbose) log.v(tag, "+++ oncreate +++"); super.oncreate(savedinstancestate); // must explicitly tell fragment manager fragment should receive call // oncreateoptionsmenu(). sethasoptionsmenu(true); // view fields if (mview == null) { mview = getactivity().getlayoutinflater() .inflate(r.layout.activity_improvisation, null); } getactivity().settitle(r.string.chapters_title); mchapters = chapterlist.get(getactivity()).getchapters(); chapteradapter adapter = new chapteradapter(mchapters); setlistadapter(adapter); mchapterselected = (textview) mview.findviewbyid(r.id.chapter_selected); mchapterselected.settext("chapter selected here"); } @override public void onlistitemclick(listview l, view v, int position, long id) { // chapter adapter chapters c = ((chapteradapter)getlistadapter()).getitem(position); //start improvisationactivity intent = new intent(getactivity(), improvisationactivity.class); i.putextra(chapterfragment.extra_chapter_id, c.getid()); i.putextra(chapterfragment.extra_keyselected, mkeyselected); startactivity(i); } @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { super.oncreateoptionsmenu(menu, inflater); inflater.inflate(r.menu.fragment_chapters_list, menu); } here xml file
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:layout_weight="2" android:layout_height="fill_parent" android:layout_width="match_parent" > <videoview android:id="@+id/video_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </linearlayout> <linearlayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="16dp" android:layout_marginright="16dp" android:orientation="horizontal" > <textview android:id="@+id/chapter_selected" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity = "center" android:textstyle="bold" android:paddingleft="4dp" android:paddingright="4dp" android:text="chapter selection" /> </linearlayout> <framelayout android:id="@+id/fragmentcontainer" android:layout_height="match_parent" android:layout_width="match_parent" /> </linearlayout>
i didn't find out why couldn't settext, displaying subtitles after user selects menu item works purposes.
Comments
Post a Comment