因此,我想从一个菜单项中显示一个允许用户输入一些文本的对话框。该对话框工作得很好,但是当我尝试对 EditText 对象执行任何操作时,应用程序会关闭。可能与我正在使用的对话框的布局有关,但我不确定。下面是按下相应菜单项时调用的方法:
private void showChangeDownloadURLDialog() {
mapShouldRefresh = false;
// Get the layout inflater
LayoutInflater inflater = MapsActivity.this.getLayoutInflater();
final EditText mEditText = (EditText) findViewById(R.id.urladdress);
new AlertDialog.Builder(MapsActivity.this)
.setTitle(R.string.map_menu_test)
.setView(inflater.inflate(R.layout.change_url, null))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "click ok");
String mString = mEditText.getEditableText().toString();
Log.i(TAG, "New URL is: " + mString);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Does nothing
}
})
.create()
.show();
}
任何帮助表示赞赏,谢谢!