我的应用程序中有一个列表视图,基本上是一个问题,所以有一些用户需要填写的EditText.我遇到了以下问题:
>一些EditText需要数字输入,所以我将inputType设置为相应的xml类型为数字,但是,当我点击EditText时,数字键盘显示,但几乎立即消失,并显示常规键盘.
>您可以想像,我需要存储用户在这些EditTexts中输入的值.我有这个问题是,在我输入一些文本在SOME EditTexts和我向下滚动后,文本消失,当我回去.你可以在我的代码中看到我试图阻止这一点,我应该提到它与复选框完全一样.
>一开始我遇到了失去焦点的问题,但是我已经解决了其他问题(添加descendantFocusablity =“beforeDescendants”到ListView和windowSoftInputMode =“adjustPan”).工作正常,除了当EditText低于屏幕的一半时,一旦我开始键入它就会失去焦点.
列表适配器的getView方法:
- public View getView(final int position,View result,ViewGroup parent)
- {
- final ViewHolder vh;
- final Question question = values.get(position);
- if(holders[position]==null)
- vh = new ViewHolder();
- else
- vh = holders[position];
- LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- if(question.getQuestionType().equals(Question.TYPE_CLOSED))
- {
- result = inflater.inflate(R.layout.closed_question_list_item,null);
- vh.cb = (CheckBox)result.findViewById(R.id.checkBox);
- vh.cb.setOnCheckedChangeListener(new OnCheckedChangeListener()
- {
- @Override
- public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
- {
- vh.isChecked = isChecked;
- holders[position] = vh;
- }
- });
- vh.cb.setChecked(vh.isChecked);
- }
- else
- {
- result = inflater.inflate(R.layout.numeric_question_list_item,null);
- vh.et = (EditText)result.findViewById(R.id.question_et);
- vh.et.addTextChangedListener(new TextWatcher()
- {
- @Override
- public void afterTextChanged(Editable s)
- {
- vh.tvValue = s.toString();
- holders[position] = vh;
- Log.i(TAG,"Entered afterTextChanged for "+ question.getText());
- }
- @Override
- public void beforeTextChanged(CharSequence s,int start,int count,int after)
- {
- }
- @Override
- public void onTextChanged(CharSequence s,int before,int count)
- {
- }
- });
- vh.et.setText(vh.tvValue);
- }
- vh.tv = (TextView)result.findViewById(R.id.question_text);
- vh.tv.setText(question.getText());
- holders[position] = vh;
- result.setTag(vh);
- return result;
- }
解决方法
发布#3的解决方案
>在列表视图中设置descendantFocusablity =“beforeDescendants”.>在清单中设置windowSoftInputMode =“adjustPan”>设置listview.setItemsCanFocus(true)