Precautions for obtaining the dialog box text for android
1. Set View to final type, for example, final View layout =...
2. Format EditText e = (EditText) layout. findViewById (R. id) when obtaining the text box object. // remember that layout is the final View object above.
You won't be able to get the text in the dialog box without looking at the above!
Private void getWifiInfo (){
// TODO Auto-generated method stub
/**
* When you press the return key, the prompt dialog box uses the default style.
*/
LayoutInflater inflater = getLayoutInflater ();
Final View layout = inflater. inflate (R. layout. dialog, (ViewGroup) findViewById (R. id. dialog ));
New AlertDialog. Builder (this ).
SetTitle ("custom layout ").
SetView (layout ).
SetPositiveButton ("OK ",
New DialogInterface. OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog, int which ){
EditText et1 = (EditText) layout. findViewById (R. id. wifiname );
EditText et2 = (EditText) layout. findViewById (R. id. wifipassword );
Wifiname = et1.getText (). toString ();
Wifipassword = et2.getText (). toString ();
}})
. SetNegativeButton ("cancel", null). show ();
}