android - FragmentTabHost return null when I get the tag of the tab -


here how create tabhost, tab when user click on tab. problem , return null instead of tag value.

    tabhost = (fragmenttabhost) findviewbyid(android.r.id.tabhost);     tabhost.setup(this, getsupportfragmentmanager(), r.id.realtabcontent);      tabhost.addtab(             tabhost.newtabspec("home").setindicator("",                     getresources().getdrawable(r.drawable.meun_home)),             homefragment.class, null);     tabhost.addtab(             tabhost.newtabspec("form").setindicator("",                     getresources().getdrawable(r.drawable.meun_register)),             formfragment.class, null);     tabhost.addtab(             tabhost.newtabspec("calculator").setindicator("",                     getresources().getdrawable(r.drawable.meun_calculator)),             calculatorfragment.class, null);     tabhost.addtab(             tabhost.newtabspec("news").setindicator("",                     getresources().getdrawable(r.drawable.meun_call)),             homefragment.class, null);      tabhost.gettabwidget().setdividerdrawable(             getresources().getdrawable(r.drawable.border));      (int = 0; < tabhost.gettabwidget().getchildcount(); i++) {         tabhost.gettabwidget().getchildat(i).setbackgroundcolor(getresources().getcolor(android.r.color.transparent));         layoutparams params = new layoutparams(layoutparams.wrap_content,                 layoutparams.match_parent, 1f);         tabhost.gettabwidget().getchildat(i).setlayoutparams(params);         tabhost.gettabwidget().getchildat(i).setpadding(0, 0, 0, 0);         tabhost.gettabwidget().getchildat(i).setontouchlistener(new ontouchlistener(){             @override             public boolean ontouch(view v, motionevent event) {                 int action = event.getaction();                 if(action == motionevent.action_up) {                                            log.d("test1",""+v.gettag());                     return true; // doesnt allow tab change                 }                 return false;             }                        });     } 

you can find line log.d("test1",""+v.gettag()); return null. expected return string "home" , "form", etc..... lot

because not set tag view of newtabspec. set drawable icon not set tag. can in 2 ways:

1) first create imageview drawable icon:

imageview.setimagebitmap(bitmap); imageview.setimageresource(r.drawable.my_image); imageview.setimagedrawable(drawable); 

and set tag imageview , use setindicator(view view) add newtabspec.

2) or after add drawable can use getchildtabviewat() view , set tag it.

in summary have not set tag null.

the doc says:

tabhost.tabspec:

a tab has tab indicator, content, , tag used keep track of it. builder helps choose among these options. tab indicator, choices are: 1) set label 2) set label , icon tab content,

so string label, tag , label 2 different things, tag memory of view can store object in object can string or else viewholder design pattern used in creating listview.


Comments

Popular posts from this blog

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -