1
私はoncreateで動的ボタンを作成しています。私はXMLにボタンを入れませんでした。アンドロイドでどのダイナミックボタンがクリックされたかを確認する方法は?
LinearLayout table = (LinearLayout)findViewById(R.id.linearlayout);
Button btnAttendance,btnSched;
btnAttendance = new Button(this);
btnSched = new Button(this);
btnAttendance.setOnClickListener(this);
btnSched.setOnClickListener(this);
table.addView(btnAttendance);
table.addView(btnSched);
//これは私が私のリスナーを実装するにcreateed私のOnClickメソッドです:
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
BackgroundWorker fetchRiddles = new BackgroundWorker(DashActivity.this,"retrieveRiddles");
switch (arg0.getId()) {
case 1: // in this case i usually put "R.id.Button1:" but my problem is that my buttons are dynamic
fetchRiddles.execute("0,"+username);
break;
case 2:
fetchRiddles.execute("1,"+username);
break;
}
スイッチを使用して、クリックされたボタンを決定するためにどのように?私のボタンは、自分のXMLの中にボタンを入れずに動的に作成されます。
をハハハ...ああ!ありがとう:o – picolo