android 文本分页显示,Android Fragment分页显示的实现

public class MainActivity extends FragmentActivity implementsView.OnClickListener {privateAllPhotosFragment allPhotosFragment;privateMyAlbumFragment myAlbumFragment;privateShareTimeFragment shareTimeFragment;privateShotTimeFragment shotTimeFragment;privateThemeAlbumFragment themeAlbumFragment;privatePersonalFragment personalFragment;privateImageView test1;privateImageView test2;privateImageView test3;privateFragmentManager fragmentManager;

@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏

setContentView(R.layout.activity_main);

test1=(ImageView) findViewById(R.id.test1);

test2=(ImageView) findViewById(R.id.test2);

test3=(ImageView) findViewById(R.id.test3);

test1.setOnClickListener(this);

test2.setOnClickListener(this);

test3.setOnClickListener(this);

fragmentManager=getSupportFragmentManager();

}

@Overridepublic voidonClick(View v) {

FragmentTransaction transaction=fragmentManager.beginTransaction();

hideFragments(transaction);switch(v.getId()) {caseR.id.test1:if (allPhotosFragment == null) {

allPhotosFragment= newAllPhotosFragment();

transaction.add(R.id.id_content, allPhotosFragment);

}else{

transaction.show(allPhotosFragment);

}break;caseR.id.test2:if (shareTimeFragment == null) {

shareTimeFragment= newShareTimeFragment();

transaction.add(R.id.id_content, shareTimeFragment);

}else{

transaction.show(shareTimeFragment);

}break;caseR.id.test3:if (personalFragment == null) {

personalFragment= newPersonalFragment();

transaction.add(R.id.id_content, personalFragment);

}else{

transaction.show(personalFragment);

}break;

}

transaction.commit();

}private voidhideFragments(FragmentTransaction transaction) {if (allPhotosFragment != null) {

transaction.hide(allPhotosFragment);

}if (shareTimeFragment != null) {

transaction.hide(shareTimeFragment);

}if (personalFragment != null) {

transaction.hide(personalFragment);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值