在做机顶盒时遇到一个问题,如何为tabhost添加点击事件,现在稍作记录,以备后用,先看代码
int tabCount = Tags.length;
for (int i = 0; i < tabCount; i++) {
mTabHost.getTabWidget().getChildAt(i).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do what you want
<span style="white-space:pre"> </span> int index = vp.getCurrentItem();
<span style="white-space:pre"> </span> Fragment fragment = (Fragment) vp.getAdapter().instantiateItem(vp, index);
<span style="white-space:pre"> </span> View view= fragment.getView();
<span style="white-space:pre"> </span> view.requestFocus();
}
});
}
基本思想就是将tab遍历一遍,为每个tab添加点击事件