Notes on text in the android get dialog box. The android get dialog box

Source: Internet
Author: User

Notes on text in the android get dialog box. The android get dialog box

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


}


How to obtain the edit box information in the dialog box in the android Program

EditText txtName = (EditText) findViewById (R. id. User Name text box ID );
String name = txtName. getText ();
Same Password
Is the layout in the dialog box taken from the XML file?
The XML should contain the ID of the text box, so there should be no problem in obtaining the text box.

In android, how does one obtain text from the Dialog box?

AlertDialog. Builder builder = new AlertDialog. Builder (this );

Builder. setMessage ("title ");

AlertDialog alert = builder. create ();
Alert. show ();
Dialog itself has nothing. What do you get?

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.