EditText inside Toast in android? -
I am creating an application in which I have to display a toast that has editing text. Is it possible to make an edit text in toast?
You must use a quick user input dialog
Steps:
Create a quick dialog layout XML file. Attach quick dialog layout to AlertDialog.builder. AlertDialog.builder attach alert alert to.
Yout layout / main_activity.exam
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical" & gt; Android: Android: Android: Android: Android: Android: Layout_Width = "Wrap-Content" Android: Layout_Height = "Wrap-content" Android: Text = "Show Prompt Dialog" / & gt; & Lt; EditText Android: id = "@ + id / editTextResult" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" & gt; & Lt; / EditText> & Lt; / LinearLayout & gt; A layout / prompts. Xml
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id / layout_root" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" android: orientation = "Vertical" Android: padding = "10dp" & gt; & Lt; TextView Android "Android: attr / textAppearanceLarge" id = "@ + id / textView1" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" android: text = "type in your message:" Android textAppearance = / & gt ; & Lt; EditText Android: id = "@ + id / editTextDialogUserInput" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" & gt; & Lt; Requestfocus / & gt; & Lt; / EditText> & Lt; / LinearLayout & gt; Your main activity:
the expansion of the public class main activity activity (final reference reference = this; personal button button; personal edit text result; public zero on Crete (bundle saved Instansstet) {Suprknkret (saved Instensstet); setContentView (R.layout.main); // component main.xml button = (button) findViewById (R.id.buttonPrompt); result = (Edit text) Find VVBIID (RID.editText Resolve); // Add Button Click the button .Set onClicklist (New OnListList () {@Override Public Zero Click on (see ARG0) {// get prompts.xml View LayoutInflator Li = Layout Inflator.Frame (reference); See PromptSwive = LE.Flat (R) . layout.prompts, nULL); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder (reference); // set alertdialog builder alertDialogBuilder.setView (promptsView prompts.xml); last EditText userInput = (EditText) promptsView .findViewById (R. Id .editTextDialogUserInput); // Set dialog message alertDialogBuilder .setCancelable (wrong) .setPositiveButton ("OK", New DialogInterface.OnClickList Ener () {Public Zero onClick (DialogInterface Dialog, Integer ID) {// Get user input and set result results // edit text result.setText (userInput.getText ());}}) .setNegativeButton ("Cancel" , New DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int id) {dialog.cancel ();}}); // Create Alert Dialog AlertDialog alertDialog = alertDialogBuilder.create (); // show this alert dialog. }}); }}
Comments
Post a Comment