I wasn't able to reproduce the warning you were getting, but wasn't able to get the Toast to appear on pressing the textbox when not focused. I did try the following to replicate what you're trying to achieve. Hopefully I understood you correctly.
EditText
Instead of using enabled="false"
I used focusable="false"
. This will have a similar behaviour to enabled being false, but allows the onClickListener
of txtPhone
to fire.
<EditText
android:id="@+id/txtPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="false"
android:hint="Telephone..."
android:inputType="phone"
android:maxLength="11" />
Listeners
Since you didn't show code for the buttons, I used a button called btnEdit
to switch between focuses. Instead of txtPhone.setFocusable(true);
I used txtPhone.setFocusableInTouchMode(true);
to properly get the edit text to be editable.
btnEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (txtPhone.isFocusable()) {
txtPhone.setFocusable(false);
} else {
txtPhone.setFocusableInTouchMode(true);
}
}
});
txtPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (txtPhone.isFocusable() == false) {
if (txtPhone.getText().length() > 1) {
// Call number
// Using Toast to show listeners working first
Toast.makeText(MainActivity.this, "Calling... " + txtPhone.getText().toString(), Toast.LENGTH_LONG).show();
}
}
}
});
So when I first start the activity, txtPhone
is not editable. When I click the edit button, txtPhone
becomes editable and I am able to enter numbers. Lastly, I click the edit button again to disable txtPhone
and when I press on it, the Toast appears.