Today I will introduce you about tricks in Android with high techniques, now can use How to set default text on EditText in Android
Create layout activity_main.xml
Create layout activity_main.xml
<RelativeLayoutCreat class Main.class
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
android:background="#e4e9e8"
>
<EditText
android:id="@+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Input your country"
android:padding="10dp"
android:text="Bangladesh"
/>
<EditText
android:id="@+id/et_city"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Input your City"
android:padding="10dp"
android:layout_below="@+id/et"
/>
</RelativeLayout>
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et = (EditText) findViewById(R.id.et);
EditText et_city = (EditText) findViewById(R.id.et_city);
// Set the default text of second EditText widget
et_city.setText("USA");
}
}
No comments:
Post a Comment