EditText as ChangeContact
EditText focus is not working in android studio, i want to hide a textview when focus change in edittext, how to do this?
ChangeContact.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
Toast.makeText(mContext, "focus loosed", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mContext, "focused", Toast.LENGTH_LONG).show();
bookLinear.setVisibility(View.GONE);
}
}
});
My edit text in XMl file
<EditText
android:id="@+id/etChangeAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginBottom="8dp"
android:background="@drawable/shape_transparent"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:hint="Address"
android:inputType="textPersonName"
android:padding="5dp"
app:layout_constraintBottom_toTopOf="@+id/etChangeNumber"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
But i cant see the Toast
Please help....
Have you tried with this for ChangeContact?
android:focusable="true"
android:focusableInTouchMode="true"
also ChangeContact.requestFocus()?
In my case I can't get on focus change event because I forgot to delete setContentView()
function and used it with binding initialization like this:
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater, null, false)
also eventually I understood that binding initialization also was incorrect
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.