Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText in ListView hidden by keyboard when focused

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?

like image 625
Till S Avatar asked Jan 29 '13 02:01

Till S


1 Answers

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.

like image 79
Archie.bpgc Avatar answered Oct 23 '22 09:10

Archie.bpgc