public void initTab(String result) { tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); try { JSONObject jsonObj = new JSONObject(result); JSONArray jsonArraySuccess = jsonObj.getJSONArray("Success"); JSONArray jsonArrayFail = jsonObj.getJSONArray("Fail"); int totalBooksBorrow = jsonArraySuccess.length() + jsonArrayFail.length(); Bundle success = new Bundle(); success.putString("Json", jsonArraySuccess.toString()); success.putInt("totalBooksBorrow", totalBooksBorrow); Bundle fail = new Bundle(); fail.putString("Json", jsonArrayFail.toString()); fail.putInt("totalBooksBorrow", totalBooksBorrow); tabHost.addTab( tabHost.newTabSpec("Success").setIndicator("Success"), SuccessBorrowBookFragment.class, success); tabHost.addTab( tabHost.newTabSpec("Fail").setIndicator("Fail"), FailBorrowBookFragment.class, fail); tabHost.setOnTabChangedListener( new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { /*Toast.makeText(ShowBorrowBooksResultActivity.this, "Tab Changed", Toast.LENGTH_SHORT).show();*/ } }); } catch (JSONException e) { e.printStackTrace(); } }
private FragmentTabHost initTabHost() { mTabHost = new FragmentTabHost(getActivity()); mTabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabhost); setupTab( CompaniesInfoFragment.class, new TextView(getActivity()), Keys.TAB_INFO, getArguments()); setupTab( CompaniesWallFragment.class, new TextView(getActivity()), Keys.TAB_WALL, getArguments()); setupTab( CompaniesNewsFragment.class, new TextView(getActivity()), Keys.TAB_NEWS, getArguments()); mTabHost.setOnTabChangedListener(this); return mTabHost; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_root); tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); tabHost.addTab( tabHost .newTabSpec("manager") .setIndicator(createTabItem("课程管理", R.drawable.ic_tab_manager)), CourseManagerFragment.class, null); View groupTabItem = createTabItem("学生群组", R.drawable.ic_tab_group); groupDot = groupTabItem.findViewById(R.id.dot); tabHost.addTab( tabHost.newTabSpec("chatlist").setIndicator(groupTabItem), ChatListFragment.class, null); tabHost.addTab( tabHost .newTabSpec("material") .setIndicator(createTabItem("教材教具", R.drawable.ic_tab_material)), TeachMaterialFragment.class, null); View mineTabItem = createTabItem("我的", R.drawable.ic_tab_mine); mineDot = mineTabItem.findViewById(R.id.dot); tabHost.addTab(tabHost.newTabSpec("mine").setIndicator(mineTabItem), MineFragment.class, null); tabHost.setOnTabChangedListener(this); // Umeng MobclickAgent.updateOnlineConfig(this); UmengUpdateAgent.silentUpdate(this); // RongCloud doRCIMConnect(3); isFirstLogin = Boolean.valueOf(getIntent().getData().getQueryParameter("isFirstLogin")); if (isFirstLogin) { startActivity("sgteacher://applyteacher?fromLogin=true"); } RongIM.setOnReceiveMessageListener(this); setSwipeBackEnable(false); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stats); // Show the Up button in the action bar. setupActionBar(); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); spec = mTabHost .newTabSpec("1") .setIndicator(null, getResources().getDrawable(R.drawable.user_icon_blue)); mTabHost.addTab(spec, StatsTabBody.class, null); spec = mTabHost .newTabSpec("2") .setIndicator(null, getResources().getDrawable(R.drawable.arm_logo)); mTabHost.addTab(spec, StatsTabExercises.class, null); mTabHost.setCurrentTab(statsTabCurrentPosition); mTabHost.setOnTabChangedListener(this); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public void initTabs() { tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent); View LoginView = LayoutInflater.from(this).inflate(R.layout.tab_login, null); tabHost.addTab( tabHost.newTabSpec(TAB_LOGIN).setIndicator(LoginView), LoginFragment.class, null); View SignInView = LayoutInflater.from(this).inflate(R.layout.tab_signin, null); tabHost.addTab( tabHost.newTabSpec(TAB_SIGNIN).setIndicator(SignInView), SignInFragment.class, null); tabHost.setOnTabChangedListener( new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { int currentTab = tabHost.getCurrentTab(); switch (currentTab) { case 0: setActive(R.id.tabLogin0); setActiveEsp(R.id.tabLogin1); setInactive(R.id.tabSignIn0); setInactiveEsp(R.id.tabSignIn1); break; case 1: setActive(R.id.tabSignIn0); setActiveEsp(R.id.tabSignIn1); setInactive(R.id.tabLogin0); setInactiveEsp(R.id.tabLogin1); break; } } }); }
@SuppressWarnings("rawtypes") private void AddTab(String tag, int title, int i, Class cls) { TabSpec tabSpec = mTabHost.newTabSpec(tag); View view = getLayoutInflater().inflate(R.layout.ic_tab_item, null); ImageView image = (ImageView) view.findViewById(R.id.tab_image); TextView textview = (TextView) view.findViewById(R.id.tab_text); textview.setText(title); image.setBackgroundResource(imagelist[i]); mTabHost.addTab(tabSpec.setIndicator(view), cls, null); mTabHost.setOnTabChangedListener( new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if (tabId.equals("3")) { if (TextUtils.isEmpty(GlobalVariable.UserID)) { showShortToast("请客官先登录"); startActivityForResult(LoginActivity.class, null, 343); } } } }); }