Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit Text in ListActivity ListView loses focus when keyboard comes up

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 EditText boxes added to a ListView that is the basis to a ListActivity. When I set the windowSoftInputMode to adjustPan and click in an EditText it works until you click on it again and then the keyboard covers it up. When I use adjustResize it works except when the keyboard comes up the EditText loses focus and I have to tap on it again to type.

I was trying to figure out how to catch the onResize but that seems to be associated with the View and not the activity and I'm not entirely sure how to listen for it. I have also tried all sorts of focusable settings on the EditText boxes and the ListView itself (as suggested in other posts I read) that don't seem to help either.

like image 630
Physibeth Avatar asked Aug 02 '11 20:08

Physibeth


People also ask

How do you make Edittext lose focus?

setOnClickListener(saveButtonListener); private OnClickListener saveButtonListener = new OnClickListener() { @Override public void onClick(View v) { Text1. clearFocus(); Text2. clearFocus(); findViewById(R. id.

How do I edit text in listview?

Configure the edittextcreate an adapter for the listview and set the position as a tag for the edittext. Normally, when scrolling the item position will change. So, you have to get the edittext tag and set it into the edittext id. from that you can avoid the change of the item position.

What is focus in Edittext?

If the return-value of the method is true, a toast is shown and the focus should get back on the EditText again. The focus should always get back on the EditText and the keyboard should show, until the return-value of the method is false.


1 Answers

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

XML:

android:descendantFocusability="afterDescendants" 

Java:

listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 
like image 147
Bojan Kseneman Avatar answered Oct 15 '22 06:10

Bojan Kseneman