android - Cannot get the position of the tabhost from a fragment to another fragment using bundle -
i have 2 fragments. 1 tab , 1 main layout calls list view. having trouble passing "position" alarmtab class alarmactivity class. position being passed gets length of array. when click list position [0] tab, returns length of mytabhost , not clicked tab. want position of clicked , below codes of have done far. i've been working hours already. can me point out missing. thank in advance!
from alarmtab class
mtabhost = (fragmenttabhost) rootview.findviewbyid(android.r.id.tabhost); widget = (tabwidget) rootview.findviewbyid(android.r.id.tabs); hs = (horizontalscrollview) rootview.findviewbyid(r.id.horizontalscrollview); mtabhost.setup(getactivity(), getchildfragmentmanager(), android.r.id.tabcontent); for(int i=0; i<smashdevicedata.get_instance().devices.size(); i++) { alarmactivity alarmactivity = new alarmactivity(); bundle bundle = new bundle(); bundle.putint("position", i); alarmactivity.setarguments(bundle); mtabhost.addtab(mtabhost.newtabspec("i").setindicator(smashdevicedata.get_instance().devices.get(i).devicename), alarmactivity.class, bundle); }
and alarmactivity class
public void addalarm(){ imageview addalarmbutton = (imageview) getactivity().findviewbyid(r.id.add_alarm); addalarmbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { fragmentactivity maindrawer = (fragmentactivity) context; fragment fragment; bundle b = getarguments(); int position = b.getint("position", 0); toast.maketext(context, string.valueof(b.getint("position")), toast.length_short ).show(); fragment = alarmsetactivity.newinstance(context, position); fragmentmanager fragmentmanager = maindrawer.getsupportfragmentmanager(); fragmenttransaction ft = fragmentmanager.begintransaction(); ft.replace(r.id.content_frame, fragment); ft.addtobackstack(null); ft.commit(); } }); }
your problem lies on line
mtabhost.addtab(mtabhost.newtabspec("i").setindicator(smashdevicedata.get_instance(). devices.get(i).devicename), alarmactivity.class, bundle);
it should this
mtabhost.addtab(mtabhost.newtabspec(smashdevicedata.get_instance(). devices.get(i).devicename).setindicator(smashdevicedata.get_instance().devices.get(i). devicename), alarmactivity.class, bundle);
Comments
Post a Comment