我想将 ArrayList 放在 onClick 方法上。但它告诉我我应该将arraylist 更改为final(我会在里面放一些东西所以不能)。我应该如何将arraylist放入其中!?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView txt1;
Button btn1;
ArrayList <String> shop= new ArrayList <String>();
impshop(shop);
txt1 =(TextView)findViewById(R.id.tv1);
btn1 =(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Random ran = new Random();
int choose = ran.nextInt(shop.size());
txt1.setText(shop.get(choose));
}});
}
我可以点击(查看 v,ArrayList 商店)吗?