java – Android:ListView中的EditText问题

前端之家收集整理的这篇文章主要介绍了java – Android:ListView中的EditText问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序中有一个列表视图,基本上是一个问题,所以有一些用户需要填写的EditText.我遇到了以下问题:

>一些EditText需要数字输入,所以我将inputType设置为相应的xml类型为数字,但是,当我点击EditText时,数字键盘显示,但几乎立即消失,并显示常规键盘.
>您可以想像,我需要存储用户在这些EditTexts中输入的值.我有这个问题是,在我输入一些文本在SOME EditTexts和我向下滚动后,文本消失,当我回去.你可以在我的代码中看到我试图阻止这一点,我应该提到它与复选框完全一样.
>一开始我遇到了失去焦点的问题,但是我已经解决了其他问题(添加descendantFocusablity =“beforeDescendants”到ListView和windowSoftInputMode =“adjustPan”).工作正常,除了当EditText低于屏幕的一半时,一旦我开始键入它就会失去焦点.
列表适配器的getView方法

  1. public View getView(final int position,View result,ViewGroup parent)
  2. {
  3. final ViewHolder vh;
  4. final Question question = values.get(position);
  5. if(holders[position]==null)
  6. vh = new ViewHolder();
  7. else
  8. vh = holders[position];
  9.  
  10. LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  11. if(question.getQuestionType().equals(Question.TYPE_CLOSED))
  12. {
  13. result = inflater.inflate(R.layout.closed_question_list_item,null);
  14. vh.cb = (CheckBox)result.findViewById(R.id.checkBox);
  15. vh.cb.setOnCheckedChangeListener(new OnCheckedChangeListener()
  16. {
  17.  
  18. @Override
  19. public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
  20. {
  21. vh.isChecked = isChecked;
  22. holders[position] = vh;
  23. }
  24. });
  25. vh.cb.setChecked(vh.isChecked);
  26. }
  27.  
  28. else
  29. {
  30. result = inflater.inflate(R.layout.numeric_question_list_item,null);
  31. vh.et = (EditText)result.findViewById(R.id.question_et);
  32. vh.et.addTextChangedListener(new TextWatcher()
  33. {
  34. @Override
  35. public void afterTextChanged(Editable s)
  36. {
  37. vh.tvValue = s.toString();
  38. holders[position] = vh;
  39. Log.i(TAG,"Entered afterTextChanged for "+ question.getText());
  40. }
  41.  
  42. @Override
  43. public void beforeTextChanged(CharSequence s,int start,int count,int after)
  44. {
  45. }
  46.  
  47. @Override
  48. public void onTextChanged(CharSequence s,int before,int count)
  49. {
  50. }
  51. });
  52. vh.et.setText(vh.tvValue);
  53. }
  54. vh.tv = (TextView)result.findViewById(R.id.question_text);
  55.  
  56. vh.tv.setText(question.getText());
  57.  
  58. holders[position] = vh;
  59. result.setTag(vh);
  60. return result;
  61. }

解决方法

发布#3的解决方

>在列表视图中设置descendantFocusablity =“beforeDescendants”.>在清单中设置windowSoftInputMode =“adjustPan”>设置listview.setItemsCanFocus(true)

猜你在找的Android相关文章