onClick
SherlockFragmentActivity
事件
Log msg Rating tab is clicked = 1
Log msg Rating tab is clicked = 2
注意::我在stackoverflow上检查了几个解决方案,但是当我使用sherlockFragmentActivity
MainActivitySherlock.java
public class MainActivitySherlock extends SherlockFragmentActivity {
// Declare Variables
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the view from main_sorting.xml
setContentView(R.layout.main_sorting);
// Locate android.R.id.tabhost in main_sorting.xml
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
// Create the tabs in main_sorting.xml
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
// Create Rating
mTabHost.addTab(mTabHost.newTabSpec("rating").setIndicator("Rating"),
FragmentRating.class, null);
// Create Price
mTabHost.addTab(mTabHost.newTabSpec("Price").setIndicator("Price"),
FragmentPrice.class, null);
// Create Distance
mTabHost.addTab(mTabHost.newTabSpec("Distance").setIndicator("Distance"),
FragmentDistance.class, null);
}
//Split ActionBar Buttons
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getSupportMenuInflater();
menuInflater.inflate(R.menu.actionbar_sort_menu, menu);
return super.onCreateOptionsMenu(menu);
}
}
如何实现这一点!
答案 0 :(得分:1)
您可以尝试将setOnTabChangedListener
设置为TabHost
。在你的情况下,
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String arg0) {
Log.i("Tab number", "" + tabHost.getCurrentTab());
});
}