设置为false后如何设置setFocusable为true?

时间:2016-10-08 19:43:56

标签: android android-edittext focusable

这是我的代码:

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

现在我想在edittext中输入一些文本。我必须将setFocuable设置为true.i已经尝试在onClick,setOnClickListener,setOnTouchListener中设置setFocusable(true)但是没有任何工作......帮帮我们;(..

2 个答案:

答案 0 :(得分: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();

}

答案 1 :(得分:0)

以编程方式

    edittext.requestFocus();

XML

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