我正在处理一个应用程序时,我必须在更改选项卡时更改一个选项卡的视图。我正在按照使用OnTabChangedListener
. 我能够替换视图。但是当我将标签更改为其他标签时,以前的视图在后台仍然可以点击?为什么会这样?在前面,填充了新视图,但是如果我点击屏幕上先前视图控件所在的任何位置,则会执行该功能。我不知道问题出在哪里。请帮帮我。谢谢!
public class FragmentTabs extends FragmentActivity implements OnTabChangeListener {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.fragment_tabs);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.setOnTabChangedListener(this);
if (Database.getSharedObject(getApplicationContext()).getAppSettings().getListView() == 1) {
mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("", getResources().getDrawable(R.drawable.home_tab)), HomeFragment.class, null);
} else {
mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("", getResources().getDrawable(R.drawable.home_tab)), CalendarViewFragment.class, null);
}
mTabHost.addTab(mTabHost.newTabSpec("groups").setIndicator("", getResources().getDrawable(R.drawable.groups_tab)), GroupFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("templates").setIndicator("", getResources().getDrawable(R.drawable.templates_tab)), TemplateFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("settings").setIndicator("", getResource
mTabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
mTabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
mTabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;
mTabHost.getTabWidget().getChildAt(3).getLayoutParams().height = height;
// Database.getSharedObject(getApplicationContext());
mTabHost.setCurrentTab(0);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
public void onTabChanged(String arg0) {
mTabHost.getCurrentTabView().invalidate();
if (mTabHost.getCurrentTab() == 0) {
if (Database.getSharedObject(getApplicationContext()).getAppSettings().getListView() == 1) {
HomeFragment homeFragment = new HomeFragment();
mTabHost.getCurrentTabView().invalidate();
getSupportFragmentManager().beginTransaction().replace(R.id.realtabcontent, homeFragment).addToBackStack(null).commit();
} else {
CalendarViewFragment calendarViewFragment = new CalendarViewFragment();
mTabHost.getCurrentTabView().invalidate();
getSupportFragmentManager().beginTransaction().replace(R.id.realtabcontent, calendarViewFragment).addToBackStack(null).commit();
}
}
}
}