How to setFocusable true after setting it to false?

橙三吉。 提交于 2019-12-10 23:32:17

问题


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;(...


回答1:


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();

}



回答2:


Programatically

    edittext.requestFocus();

XML

<EditText...>
   <requestFocus />
</EditText>


来源:https://stackoverflow.com/questions/39936642/how-to-setfocusable-true-after-setting-it-to-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!