android - How to refresh fragment on spinner on item selected -
i setting language in spinner on item selected. change not reflected on next line. so, want refresh fragment.
public class todaychapter extends fragment { string chapter_verse = ""; textview textview; listview todaychapterlistview; arrayadapter<string> adapter; dailyquranmethods dailyquranmethods = new dailyquranmethods(); private final string[] translatelanguage={"translate to","english","urdu","hindi"}; public todaychapter() { // required empty public constructor } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view view = inflater.inflate(r.layout.fragment_today_chapter, container, false); todaychapterlistview = (listview)view.findviewbyid(r.id.today_chapter_list_view); spinner spinner = (spinner)view.findviewbyid(r.id.selectlanguage); arrayadapter<string> spinnerarrayadapter = new arrayadapter<string>(getactivity().getbasecontext(), android.r.layout.simple_spinner_item, translatelanguage ); spinnerarrayadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); // drop down view spinner.setadapter(spinnerarrayadapter); spinner.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { switch (position) { case 0: dailyquranmethods.settranslationlanguage(getactivity().getbasecontext(), "english"); break; case 1: dailyquranmethods.settranslationlanguage(getactivity().getbasecontext(),"english"); break; case 2: dailyquranmethods.settranslationlanguage(getactivity().getbasecontext(),"urdu"); break; default: dailyquranmethods.settranslationlanguage(getactivity().getbasecontext(),"hindi"); break; } } @override public void onnothingselected(adapterview<?> parent) { } }); string[] chapter = dailyquranmethods.getchapter(dailyquranmethods.getchapternotoday(getactivity().getbasecontext()), dailyquranmethods.gettranslationlanguage(getactivity().getbasecontext()), getactivity()); string chaptername = getactivity().getresources().getstringarray(r.array.chapters_name_arabic)[dailyquranmethods.getchapternotoday(getactivity().getbasecontext()) - 1 ]; textview textview = (textview)view.findviewbyid(r.id.chaptername); textview.settext(chaptername); adapter = new arrayadapter<string>(getactivity(),android.r.layout.simple_list_item_1,chapter); todaychapterlistview.setadapter(adapter); return view; } }
i can call method on each on item selected change. but, want refreshing fragment. in each switch case, want refresh fragment. please me solve this.
edit 1:
there 3 fragments, attached main activity:
mtabhost.setup(this, getsupportfragmentmanager(), r.id.realtabcontent); mtabhost.addtab(mtabhost.newtabspec("tab1").setindicator("today's verse"), todayverse.class, null); mtabhost.addtab(mtabhost.newtabspec("tab2").setindicator("today's chapter"), todaychapter.class, null); mtabhost.addtab(mtabhost.newtabspec("tab3").setindicator("complete qur'an"), completequran.class, null);
you can detach , attach fragment below
fragment currentfragment = getfragmentmanager().findfragmentbytag("tab2"); fragmenttransaction fragtransaction = getfragmentmanager().begintransaction(); fragtransaction.detach(currentfragment); fragtransaction.attach(currentfragment); fragtransaction.commit();
this refresh view , locale change
Comments
Post a Comment