最简单直接碎片操作,动态增删改(2)

  1. 接续文章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;
		}
	}


你可能感兴趣的:(android,Fragment)