After an unsuccessful attempt to create an interface with EditTexts inside a ListView , all I can tell you is "Do not!". You will have more problems when you have enough items that you need to scroll through the ListView , the focus will jump here and there, you need to save the EditText state and so on. It seems like the general idea is that using EditText in a ListView not worth it.
After a little research, I can suggest the following method that helped me: I inherited the ListView and redefined the layoutChildren method, inside it I do the following:
@Override protected void layoutChildren() { super.layoutChildren(); final EditText tv = (EditText)this.getTag(); if (tv != null) { Log.d("RUN", "posting delayed"); this.post(new Runnable() { @Override public void run() { Log.d("RUN", "requesting focus in runnable"); tv.requestFocusFromTouch(); tv.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , tv.getWidth(), tv.getHeight(), 0)); tv.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , tv.getWidth(), tv.getHeight(), 0)); } }); } }
When I know which EditText should get focus (I know this when my getView adapters are called), I set this particular EditText as a ListView tag. Then the ListView pops up, and my post column is queued. It starts and asks for focus, however, since this was not enough in my case, I also create two MotionEvents that simply simulate taps. Apparently, this is enough to display a soft keyboard. The reasons for this are explained in the answer here: Android action bar tabs and keyboard focus
source share