如何删除或清除EditText专注于listview单击android java

时间:2019-04-05 17:42:30

标签: java android android-edittext focus

大家好,我想在用户单击ListView时删除或清除EditText焦点。每个答案将不胜感激。

  

当用户单击listview时,它会转到fragment_detail.xml,我也将这些属性放入但不起作用。 android:focusable =“ true”       android:focusableInTouchMode =“ true”

用户单击的那个片段我也放置了view.clearFocus();但不起作用

谢谢大家。

3 个答案:

答案 0 :(得分:0)

在您的xml文件中添加以下内容。

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <requestFocus/>
</LinearLayout>

答案 1 :(得分:0)

我使用此代码。此代码关闭键盘并清除edittext focuse。 试试这个;

editText.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View view, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER) {
                    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
                    imm.hideSoftInputFromWindow(URLText.getWindowToken(), 0); 
                    editText.setFocusable(false);
                    editText.setFocusableInTouchMode(true);
                    return true;
                } else {
                    return false;
                }
            }
        });

答案 2 :(得分:0)

我以编程方式进行操作,它可以消除焦点和键盘。

editText.clearFocus();
editText.setShowSoftInputOnFocus(false);
相关问题