10

I have a ListView containing rows with EditText's.

When I click on an EditText and it's not already focused it receives focus, the keyboard appears and the EditText is moved above the CandidateView (desired behaviour).

However when I make a key press, the EditText maintains focus and receives the input but moves down and is obscured by the keyboard (the previous movement is reversed).

When I click on the EditText when it is already selected without the keyboard shown, the keyboard pops up but the EditText is not moved to the right position (above the CandidateView). It still receives the input.

I add a header view containing EditText's and there everything works correctly.

This is the code of my ArrayAdapter where the row view is created:

View view = inflater.inflate(R.layout.row_profile_entry_text, null);


final String question = getItem(position);

TextView textViewQuestion = (TextView) view.findViewById(R.id.rpeq_TextViewQuestion);
textViewQuestion.setText(question);

final EditText editTextAnswer = (EditText) view.findViewById(R.id.rpeq_EditTextAnswer);

editTextAnswer.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    }

    @Override
    public void afterTextChanged(Editable s) {
        mAnswers.put(question, s.toString());
    }
});

if (mAnswers.containsKey(question)) {
    editTextAnswer.setText(mAnswers.get(question));
}

return view;

I would also like to emphasize that I already added
android:windowSoftInputMode="adjustPan" to the Manifest and
android:descendantFocusability="beforeDescendants" to the ListView as most of the answers to other questions suggest.

Without adjustPan the EditText is not able to receive focus at all but it does not solve the issue entirely.

Does someone have an idea what I am doing wrong?

Caio Faustino
  • 165
  • 1
  • 15
Till S
  • 455
  • 5
  • 15
  • I was also facing the same issue,I didnt found any solution to this. Thats y I created my own custom keyboard due to time for R n D issue. but its not the solution.Let e upvote it.lets see what you find here. – Narendra Pal Jan 29 '13 at 02:48
  • Related/dupe: [Focusable EditText inside ListView](http://stackoverflow.com/q/2679948) – blahdiblah Oct 31 '13 at 23:48

2 Answers2

1

Try this:

<activity name="YourActivity"
    android:windowSoftInputMode="stateVisible|adjustResize|adjustPan">
</activity>

in the manifest file.

Most probably, adjustResize must work, if you are using a ScrollView.

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • It doesn't work. Now the initial move to the right position is not happening any more. Do you mean I should put the ListView in a ScrollView or only use a ScrollView and abandon the ListView? – Till S Jan 29 '13 at 06:39
  • 1
    If you are using a `ListView`, thats enought, it must scroll up automatically to stay above the softkeyboard. Just use `stateVisible|adjustResize`.But let me check with a sample project. – Archie.bpgc Jan 29 '13 at 06:42
  • 1
    Nope. `adjustResize` causes the EditText to receive focus for a very short moment (suggestions are adjusted) but it instantly looses it again and I am not able to enter anything. So far `adjustPan` is the only flag which makes the EditText focusable. – Till S Jan 29 '13 at 22:58
0

after many hours spent on this problem this is my solution (for Android < 4.2):

1) Manifest => android:windowSoftInputMode="adjustPan"

2) Activity=> create OnTouchListner and pass to Adapter

    private OnTouchListener exampleOnTouchListener = new OnTouchListener() {

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (MotionEvent.ACTION_UP == event.getAction()) {
            int position = (Integer) v.getTag();
            myListView.setSelection(position);
        }
        return false;
    }
    };

3) Adapter

        if (exampleOnTouchListener!= null) {
        myEditText.setTag(position);
        myEditText.setOnTouchListener(exampleOnTouchListener);

        // if last element set padding bottom for spacing
        if (position == items.size() - 1) {
            LinearLayout myLinearLayout = (LinearLayout) convertView
                    .findViewById(R.id.ticketcontolProposedRealvalueLinearLayout);
            myLinearLayout.setPadding(0, 0, 0,SET_PADDING_BOTTOM);
        }
        }
Krinet
  • 1