快捷导航

用了例程的源码 为什么tab的内容没有显示??

packagecom.example.ghost.text1;importandroid.os.Bundle;importandroid.support.v4.app.Fragment;importandroid.support.v4.app.FragmentActivity;importandroid.support.v4.app.FragmentManager;importandroid.support.v4.app.FragmentTransaction;importandroid.view.View;importandroid.view.Window;importandroid.widget.ImageView;importandroid.widget.LinearLayout;importandroid.widget.TextView;/***CreatedbyGHOSTon2017/1/28.*Fragment*/publicclasstabActivityextendsFragmentActivityimplementsView.OnClickListener{//四个tab布局privateLinearLayouttakeOutLayout,expressLayout,personLayout,nearbyLayout;//底部标签切换的FragmentprivateFragmenttakeOutFragment,expressFragment,personFragment,nearbyFragment;//底部标签图片privateImageViewtakeOutImg,expressImg,nearbyImg,personImg;privateTextViewtakeoutTv,expressTv,nearbyTv,presonTv;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.main_menu);initView();initEvent();setSelect(0);}privatevoidinitEvent(){takeOutLayout.setOnClickListener(this);expressLayout.setOnClickListener(this);nearbyLayout.setOnClickListener(this);personLayout.setOnClickListener(this);}privatevoidinitView(){takeOutLayout=(LinearLayout)findViewById(R.id.id_tab_takeout);expressLayout=(LinearLayout)findViewById(R.id.id_tab_express);nearbyLayout=(LinearLayout)findViewById(R.id.id_tab_nearby);personLayout=(LinearLayout)findViewById(R.id.id_tab_person);takeOutImg=(ImageView)findViewById(R.id.id_tab_takeout_img);expressImg=(ImageView)findViewById(R.id.id_tab_express_img);nearbyImg=(ImageView)findViewById(R.id.id_tab_nearby_img);personImg=(ImageView)findViewById(R.id.id_tab_person_img);}privatevoidsetSelect(inti){FragmentManagerfm=getSupportFragmentManager();FragmentTransactiontransaction=fm.beginTransaction();hideFragment(transaction);//把图片设置为亮的//设置内容区域switch(i){case0:if(takeOutFragment==null){takeOutFragment=newtab1_fragment();transaction.add(R.id.id_content,takeOutFragment);}else{transaction.show(takeOutFragment);}takeOutImg.setImageResource(R.drawable.tab_1);break;case1:if(expressFragment==null){expressFragment=newtab2_fragment();transaction.add(R.id.id_content,expressFragment);}else{transaction.show(expressFragment);}expressImg.setImageResource(R.drawable.tab_2);break;case2:if(nearbyFragment==null){nearbyFragment=newtab3_fragment();transaction.add(R.id.id_content,nearbyFragment);}else{transaction.show(nearbyFragment);}nearbyImg.setImageResource(R.drawable.tab_3);break;case3:if(personFragment==null){personFragment=newtab4_fragment();transaction.add(R.id.id_content,personFragment);}else{transaction.show(personFragment);}personImg.setImageResource(R.drawable.tab_4);break;default:break;}transaction.commit();}privatevoidhideFragment(FragmentTransactiontransaction){if(takeOutFragment!=null){transaction.hide(takeOutFragment);}if(expressFragment!=null){transaction.hide(expressFragment);}if(nearbyFragment!=null){transaction.hide(nearbyFragment);}if(personFragment!=null){transaction.hide(personFragment);}}@OverridepublicvoidonClick(Viewv){resetImgs();switch(v.getId()){caseR.id.id_tab_takeout:setSelect(0);break;caseR.id.id_tab_express:setSelect(1);break;caseR.id.id_tab_nearby:setSelect(2);break;caseR.id.id_tab_person:setSelect(3);break;default:break;}}privatevoidresetImgs(){takeOutImg.setImageResource(R.drawable.tab_1_1);expressImg.setImageResource(R.drawable.tab_2_2);nearbyImg.setImageResource(R.drawable.tab_3_3);personImg.setImageResource(R.drawable.tab_4_4);}}packagecom.example.ghost.text1;importandroid.os.Bundle;importandroid.support.v4.app.Fragment;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;publicclasstab1_fragmentextendsFragment{publicViewonCreate(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){returninflater.inflate(R.layout.tab01,container,false);}}

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2

是不是默认显示哪个界面的问题
回复

使用道具 举报

代码贴全一点好吗,这样怎么看,提问的时候设置一下代码语言,不要直接复制粘贴
回复

使用道具 举报

可能感兴趣的问答

发新帖
TA的信息
  • 会员所属: 注册会员
  • 认证信息: 邮箱认证手机认证
  • 微信访问
  • 手机APP