我在EditText
中有AlertDialog
,它用于编辑从游标获取的数据。在编辑之前,我想在EditText
中显示旧数据。从ContextMenu
项目调用以下方法:
private void edit(final long rowId){
LayoutInflater inflater = LayoutInflater.from(this);
final View editView = inflater.inflate(R.layout.add_dialog,null);
new AlertDialog.Builder(this)
.setTitle("Edit: " + cursor.getString(1))
.setView(editView)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
EditText nameView = (EditText)editView.findViewById(R.id.nameView);
//why the following statement can't work?
nameView.setText(cursor.getString(1));
editData(rowId, nameView.getText().toString());
}
})
.setNegativeButton("Cancel",null)
.show();
}
我认为应该在创建对话框之前设置它,所以我试图将该语句移到别处,但是失败了。