我有一个 ListView,其中包含带有 EditText 的行。
当我点击一个 EditText 并且它还没有获得焦点时,它会获得焦点,键盘出现并且 EditText 移动到 CandidateView 上方(期望的行为)。
但是,当我按下按键时,EditText 保持焦点并接收输入但向下移动并被键盘遮挡(之前的移动是相反的)。
当我在没有显示键盘的情况下单击已选中的 EditText 时,键盘弹出但 EditText 没有移动到正确的位置(在 CandidateView 上方)。它仍然接收输入。
我添加了一个包含 EditText 的标题 View ,一切正常。
这是创建行 View 的 ArrayAdapter 的代码:
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;
我还要强调一下,我已经添加了
android:windowSoftInputMode="adjustPan"
到 list 和
android:descendantFocusability="beforeDescendants"
正如其他问题的大多数答案所暗示的那样,到 ListView。
没有adjustPan
EditText 根本无法获得焦点,但并不能完全解决问题。
有人知道我做错了什么吗?
最佳答案
试试这个:
<activity name="YourActivity"
android:windowSoftInputMode="stateVisible|adjustResize|adjustPan">
</activity>
在 list 文件中。
如果您使用的是 ScrollView
,adjustResize
很可能必须起作用。
关于android - ListView 中的 EditText 在聚焦时被键盘隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14574546/