我有什么:
我想知道的事情:我想检测每个标签的onClick
事件并根据它执行某些操作
Fragment1.java :
public class Fragment1 extends SherlockFragment{
private FragmentTabHost mTabHost;
//Mandatory Constructor
public Fragment1() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment1,container, false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Rating"),
RatingAscending.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Price"),
PriceAscending.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragmentd").setIndicator("Distance"),
DistanceAscending.class, null);
return rootView;
}
}
答案 0 :(得分:0)
我假设你想要做的是检测你的FragmentTabHost中点击了一个特定标签的时间。这可以通过添加setOnTabChangedListener来完成。 这是一个例子:
FragmentTabHost t = new FragmentTabHost(getActivity());
t.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
// TODO your actions go here
}
});
}