Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setFocusable true after setting it to false?

here is my code:

 mEditText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
                mEditText.setFocusable(false);
                mEditText.setCursorVisible(false);
         }
});

Now i want to enter some text into edittext.for which i have to setFocuable to true.i already tried to setFocusable(true) in onClick , setOnClickListener , setOnTouchListener but nothing is working...help me guys;(...

like image 768
Ajay Chauhan Avatar asked Oct 28 '25 03:10

Ajay Chauhan


1 Answers

after searching for hours.i came up with solution- Xml Code:

<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/et"
android:setFocusable="false"
android:onClick="myFunction"/>

Put this java code inside your java file:

public void myFuction(View v){
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.requestFocus();

}
like image 61
Ajay Chauhan Avatar answered Oct 30 '25 14:10

Ajay Chauhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!