我有 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();
}
我认为它应该在创建对话框之前设置,所以我试图将该语句移到其他地方,但失败了。