Precautions for obtaining the dialog box text for android

Source: Internet
Author: User

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 ();


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.