我有这样的代码,我想在点击后删除图像视图。我使用相对布局。我必须做什么?我必须删除它而不是隐藏它,因为我有很多图像视图并且我想销毁它以便程序可以更快地运行。
banyakmusuh= new CountDownTimer(50000,1500) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
Random a = new Random();
int posisix = a.nextInt(500);
btn = new ImageView(level2.this);
btn.setImageResource(R.drawable.salju);
i= i+1;
btn.setId(i);
RelativeLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.setMargins(posisix, 0, 0, 0);
btn.setLayoutParams(params);
RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.tingkat2);
linearLayout.addView(btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
data.nilai+=10;
TextView score1 = (TextView) findViewById(R.id.skore);
score1.setText(String.valueOf(data.nilai));
//what the code for delete imageview?
//some people say to write this code but it cant, there are a green line when i debug it
//((RelativeLayout)v.getParent()).removeView(v);
}
});
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
//banyakmusuh.start();
}
}.start();