现在,当我按下对话框的 OK 按钮时,我只能看到获取的值。但是我想在警报对话框出现时看到它。我知道我已将显示代码放入 .setPositiveButton("OK", 但即使我尝试在此之前放入它,它也不起作用。我有些想法我需要使用这个 setview(addView) 但不要知道怎么做。请帮帮我。
enter code here
private void populateFields() {
LayoutInflater inflater=LayoutInflater.from(this);
final View addView=inflater.inflate(R.layout.add_country, null);
new AlertDialog.Builder(this)
.setTitle("Edit country/year")
.setView(addView)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton) {
Cursor c =
getContentResolver().query (CONTENT_URI.buildUpon ().appendPath(String.valueOf(mRowId)).build(), null, null, null, null);
/* Read alert input */
EditText editCountry =(EditText)addView.findViewById(R.id.editCountry);
EditText editYear =(EditText)addView.findViewById(R.id.editYear);
//System.out.println(c.getString(c.getColumnIndex("country")));
editCountry.setText(c.getString(c.getColumnIndex("country")));
editYear.setText(c.getString(c.getColumnIndex("year")));
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton) {
// ignore, just dismiss
}
})
.show();
}