I have a CheckBox that enables/disables a couple of EditText views. At first, when the activity is started, I'm able to click on the EditText, but when I press the CheckBox (sets enabled to false) and then press the checkbox again(which supposedly sets the EditText to enabled), I can't click on the EditText.
This is the java code
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
final EditText etPersonTitle = (EditText)v.findViewById(R.id.et_person_title);
final EditText etFirstname = (EditText)v.findViewById(R.id.et_first_name);
final EditText etSurname = (EditText)v.findViewById(R.id.et_surname);
if(isChecked){
etPersonTitle.setText(R.string.unknown);
etFirstname.setText(R.string.unknown);
etSurname.setText(R.string.unknown);
}
else {
etPersonTitle.setText("");
etFirstname.setText("");
etSurname.setText("");
}
etPersonTitle.setEnabled(!isChecked);
etPersonTitle.setFocusable(!isChecked);
etFirstname.setEnabled(!isChecked);
etFirstname.setFocusable(!isChecked);
etSurname.setEnabled(!isChecked);
etSurname.setFocusable(!isChecked);
}
and here is the xml:
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="@string/title" />
<EditText
android:id="@+id/et_person_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textPersonName"
android:textAppearance="?android:attr/textAppearanceSmall" >
</EditText>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="@string/first_name" />
<EditText
android:id="@+id/et_first_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textPersonName"
android:textAppearance="?android:attr/textAppearanceSmall" >
</EditText>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="@string/surname" />
<EditText
android:id="@+id/et_surname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textPersonName"
android:textAppearance="?android:attr/textAppearanceSmall" >
</EditText>
</TableRow>
<LinearLayout
android:id="@+id/ll_unknown_customer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="@string/unknown_customer" />
<CheckBox
android:id="@+id/cb_unknown_customer"
style="@style/checkbox_style"
android:background="@drawable/checkbox_background"
android:button="@null"
android:checked="false" />
</LinearLayout>
one thing to note is that the TableLayout is inside a ScrollView. I'm not sure if that's what's causing this issue, but that's my first suspicion.
I tried to setClickable(true) but it doesn't work either.
Thanks in advance.