【发布时间】:2012-09-05 03:49:44
【问题描述】:
我正在从列表视图中打开一个警报对话框(3 个选项和 2 个按钮)
我有这个:
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);// ass
inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_dialog,null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Select");
builder.setCancelable(true);
builder.setSingleChoiceItems(tonos, -1,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Log.d(TAG, "Option: " + tonos[item]);
tone=tonos[item];
Button botonOK = (Button) findViewById(R.id.botOK);
try {
botonOK.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d(TAG,"button ok");
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d(TAG, "Exception " + e);
}
}
});
alert = builder.create();
alert.show();
}
第二个 onClick 的参数是否正确? 我正在疯狂测试,但我找不到解决方案。
【问题讨论】:
-
代码中没有自定义对话框布局,这里
-
你在哪一行得到 NullPointer?
-
@Carnal 在这里 --> botonOK.setOnClickListener(new OnClickListener()
标签: android button dialog listener