ボタンを見つけるのに問題があります。AlertDialog
5つのオプションのいずれかを選択する場所があります。オプションを選択すると、クリックしたボタンの色を変更できます。内部のxmlファイルでボタンを宣言しましたが、メソッド<RealativeLayout>
を使用してID(IDは「id1」、「id2」のようなものです...)でボタンを見つけようとすると、エラーが発生し、できないというエラーが表示されますfindViewById
私のようにこの方法を使用します:
AlertDialog.Builder builder = new AlertDialog.Builder(StartGameActivity.this);
builder.setTitle(R.string.pickColor);
builder.setItems(R.array.colorArray, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Button btn_tmp;
String theButtonId = "id";
theButtonId = theButtonId+(String.valueOf(which));
btn_tmp = (Button) findViewById(theButtonId);
}
});
どうすればそれを修正できますか、それとも他の方法を使用する必要がありますか?
編集:
私は私の問題を解決したと思います。ボタンのメソッドの 1 つを使用しました: getId() 次のように:
final int id = clickedButton.getId();
final ImageButton btn_tmp;
btn_tmp = (ImageButton)findViewById(id);