Edit Text in ListActivity ListView loses focus when keyboard comes up

前端 未结 7 1031
挽巷
挽巷 2020-12-03 05:09

I have searched and searched for an answer to this question and everything that looked like an answer has not worked so I guess I will just ask.

I have a couple of <

相关标签:
7条回答
  • 2020-12-03 05:17

    For me a combination of the following helped me (especially number 3):

    1) Add the following to the related Activity in the manifest file, this is required for your ListView to be resized to fill only the area above the softKeyboard:

    android:windowSoftInputMode="adjustResize"
    

    2) With the below the ListView will ONLY get focus only if none of its descendants want it. The descendants (the EditText) needs to get and keep focus.

    <ListView
    ...
    android:descendantFocusability="afterDescendants"/>
    

    3) The automatic showing/hiding of the Spelling Suggestions bar right above the keyboard keeps triggering the ListView to refresh. I turned the Suggestions off for any EditText in my ListView.

    <EditText
    ...
    android:inputType="textNoSuggestions|textVisiblePassword" />
    
    0 讨论(0)
  • 2020-12-03 05:24

    recycler view works best and no need to mess around with any other properties anywhere.

    0 讨论(0)
  • 2020-12-03 05:25

    I have experienced exactly the same issue in my project.

    To resolve the issue I have subclassed the EditText and handled the "Back" button press - to make sure that my EditTextclears focus at that moment.

    Check this solution, on how to do it.

    Good luck.

    0 讨论(0)
  • 2020-12-03 05:29
    mViewHolder.editText = (EditText)convertView.findViewById(R.id.editText1);
                mViewHolder.editText.setTag(position);
                mViewHolder.editText.setTextColor(0xFF000000);
                mViewHolder.editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (!hasFocus) {
                            EditText et =(EditText)v.findViewById(R.id.editText1);
                            editTextArrayList.set(position,et.getText().toString().trim());
                        }
                    }
                });
    

    Hi below link may help for you http://mylearnandroid.blogspot.in/2014/06/listview-problem-while-scrolling.html

    0 讨论(0)
  • 2020-12-03 05:32

    All you really need to do is apply this to your ListView:

    XML:

    android:descendantFocusability="afterDescendants"
    

    Java:

    listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    
    0 讨论(0)
  • 2020-12-03 05:32

    In my case it perfect worked with adding this like of code to manifest:

    android:windowSoftInputMode="adjustPan"
    
    0 讨论(0)
提交回复
热议问题