Thanks in advance.
This is my sample code. Whenever i try to run it and change the screen orientation both the edit text disappears and i have to restart the application.
please help me out
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed1=(EditText)findViewById(R.id.ed1);
ed2=(EditText)findViewById(R.id.ed2);
ed1.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
public void afterTextChanged(Editable arg0) {
ed2.setVisibility(View.INVISIBLE);
}
});
ed2.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
public void afterTextChanged(Editable arg0) {
ed1.setVisibility(View.INVISIBLE);
}
});
}
This is my main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="25dip"
android:stretchColumns="0,1" >
<TableRow>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:text="Edit Text 1"
android:textSize="15dip" />
<EditText
android:id="@+id/ed1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="20dip"
android:maxLength="10"
android:numeric="integer|decimal" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/or_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:text="OR"
android:textSize="20dip" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:text="Edit Text2"
android:textSize="15dip" />
<EditText
android:id="@+id/ed2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="20dip"
android:maxLength="10"
android:numeric="integer|decimal" />
</TableRow>
</TableLayout>
Every time you rotate your device your activity restarts, that is why you do not see your EditTexts.
Add this line of XML to your activity in Manifest file
Also check this out to know more about Runtime changes to your applications.