- 接续文章1的主activity,新增两个按钮一个是删除,一个是恢复然后添加事件,代码如下:
@SuppressLint("Recycle") @Override public void onClick(View v) { // TODO Auto-generated method stub FragmentTransaction trx = getSupportFragmentManager() .beginTransaction(); switch (v.getId()) { case R.id.sbutton1: trx.hide(fragmentno1).commit(); Toast.makeText(getApplicationContext(), "删除", Toast.LENGTH_LONG) .show(); break; case R.id.sbutton2: trx.show(fragmentno1).commit(); Toast.makeText(getApplicationContext(), "恢复", Toast.LENGTH_LONG) .show(); break; default: break; } }
最简单直接碎片操作,动态增删改(2),布布扣,bubuko.com
时间: 2024-10-13 22:47:30