【发布时间】:2013-01-12 12:43:12
【问题描述】:
我有一个 ListView,其中包含带有 EditText 的行。
当我点击一个 EditText 并且它尚未获得焦点时,它会获得焦点,键盘会出现并且 EditText 被移动到 CandidateView 上方(期望的行为)。
但是,当我按下按键时,EditText 保持焦点并接收输入,但向下移动并被键盘遮挡(之前的移动是相反的)。
当我在没有显示键盘的情况下已经选择了 EditText 时单击它,键盘会弹出,但 EditText 没有移动到正确的位置(CandidateView 上方)。它仍然接收输入。
我添加了一个包含 EditText 的标题视图,并且一切正常。
这是创建行视图的 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" 添加到 Manifest 并将 android:descendantFocusability="beforeDescendants" 添加到 ListView,正如其他问题的大多数答案所暗示的那样。
没有adjustPan,EditText 根本无法获得焦点,但它并不能完全解决问题。
有人知道我做错了什么吗?
【问题讨论】:
-
我也面临同样的问题,我没有找到任何解决方案。那是因为 R n D 问题,我创建了自己的自定义键盘。但它不是解决方案。让我们为它投票吧。让我们看看你在这里找到了什么。
标签: android listview focus android-edittext