how to make Edite Text in android

how to make Edite Text in Android

In an android, EditText use for making a user interface Control to user update and Edite our content in any application and any form. In case the input is "number" then we need to specify the inputType as “number”.

Create an EditText in Layout File.

Following is the sample way to define EditText control in the XML layout file in the android application.

 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
android:layout_width="match_parent"
    
android:layout_height="match_parent"
    
android:orientation="vertical" >
    <
EditText
        
android:id="@+id/txtSub"
        
android:layout_width="match_parent"
        
android:layout_height="wrap_content"
        
android:hint="Subject"
        
android:inputType="text"/>
</
LinearLayout>

Create EditText Control in Activity File

In android, we can create EditText control programmatically in an activity file to allow users to enter text based on our requirements. 

 

Following is the example of creating EditText control dynamically in an activity file.





public class MainActivity extends AppCompatActivity {
    
@Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);
        EditText et = (EditText) findViewById(R.id.
txtSub);
        String name = et.getText().toString();
    }
}





Note: Next tutorial is Button In android coming..............

Comments

Popular posts from this blog

How to Integrate or Work with Open Street Map (OSM) in an Android App (Kotlin)

ListView in android with api and volley Network Library in android Studio.

how to implement OpenStreetMap in android