我想在运行时更改 AlertDialog 中的文本,但它还没有真正起作用。
由于我使用的是自定义布局,我认为我可以这样做,
AlertDialog.Builder dialog_item_detail = new AlertDialog.Builder(this);
LayoutInflater inflate_dialog = getLayoutInflater();
TextView mjollnir_descr = (TextView)findViewById(R.id.dialog_item_descr);
mjollnir_descr.setText(R.string.item_detail_mjollnir_descr);
dialog_item_detail.setIcon(R.drawable.item_clarity);
dialog_item_detail.setView(inflate_dialog.inflate(R.layout.item_dialog, null));
dialog_item_detail.create();
dialog_item_detail.setTitle(R.string.dialog_item_detail_title_clarity);
//dialog_item_detail.setCancelable(true);
dialog_item_detail.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
}
});
dialog_item_detail.show();
但如上所述,它不起作用。我总是在上面代码的第二行收到这个错误:
03-31 19:45:25.261: E/AndroidRuntime(781): FATAL EXCEPTION: main
03-31 19:45:25.261: E/AndroidRuntime(781): java.lang.IllegalStateException: Could not execute method of the activity
03-31 19:45:25.261: E/AndroidRuntime(781): Caused by: java.lang.NullPointerException
03-31 19:45:25.261: E/AndroidRuntime(781): at com.myapp.ItemsOverview.show_details_mjollnir(ItemsOverview.java:81)