Thursday 15 October 2015

Android: Accessing values in the EditText [ TextBox ]

      Android comes up with the element EditText that's the textbox. In android with EditText you could perform all kinds of operations that you do on textbox in Desktop applications which mainly includes getting and setting the values from the textbox! In this tutorial you're gonna learn how to use EditText for your android application.


      *Copy and paste the java code in your activity class; where you want to access the textbox. And the xml code in your corresponding layout xml file.

Java:
 EditText txtBox = (EditText ) findViewById(R.id.edittext1);  
 String text = txtBox.getText().toString();// to get value from the textBox  
 txtBox.setText(“Welcome”);// to set value to the textBox  

XML:
<EditText  
     android:id="@+id/edittext1"  
     android:layout_width="match_parent"  
     android:layout_height="150dp"  
     android:hint="Description"  
     android:textAppearance="?android:attr/textAppearanceMedium" />  

No comments:

Post a Comment