我想要獲取AlertDialog中的text字符串,沒實現:
private void showAddSectorDlg() {
if (BuildConfig.DEBUG) {
Log.i(Constants.TAG_ACTSECTORS, "showAddSectorDialog() called.");
}
LayoutInflater inflater = getLayoutInflater();
new AlertDialog.Builder(ActSectors.this)
.setTitle(R.string.menu_new_sector)
.setMessage(R.string.dlg_sect_add_msg)
.setView(inflater.inflate(R.layout.dlg_sector_add, null))
.setPositiveButton(R.string.dlg_save,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int whichButton) {
EditText mNewSectorName = (EditText) findViewById(R.id.dlg_edt_nsector);
//NullPointerException happens here:
String val = mNewSectorName.getText().toString();
if (BuildConfig.DEBUG) {
Log.i(Constants.TAG_ACTSECTORS, "New Sector Name: "+val);
}
grabVal(val);
dialog.dismiss();
}
})
.setNegativeButton(R.string.dlg_cancel,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int whichButton) {
}
}).create().show();
}
private void grabVal(String newSector){
mNSN = newSector;
callCtlr(Constants.R_DB_ADDSECT);
}
請高手幫忙。謝謝
inflater.inflate(R.layout.dlg_sector_add, null)把這個動作放在`new AlertDialog.Builder`之前, 類似`
final View v = li.inflate(R.layout.edit_1, null);`
記得前面要加上final,然後再setview,後面的方法就沒什麼區別了