我在我的应用程序中有一个基本上是问卷调查的列表视图,所以有一些用户需要填写的EditTexts。我遇到了以下问题:Android:在ListView问题中的EditText
一些EditText上都需要数字输入,所以我设置的inputType在相应的XML类型的数字,但是,当我点击的EditText如图所示的数字键盘但几乎立即消失,并显示常规键盘。
正如你可以想象的,我需要存储用户在这些EditTexts中输入的值。我遇到的问题是,在我输入了一些EditTexts中的文本后,向下滚动,当我回去时,文本消失了。你可以在我的代码中看到我试图阻止这种情况,我应该提到它用复选框完美地工作。
在开始时我有失去焦点的问题,但我解决了它在查看其他问题(在ListView和windowSoftInputMode =“adjustPan”中添加了descendantFocusablity =“beforeDescendants”)。除了当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 start,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; }
也许这可以帮助你 http://stackoverflow.com/questions/8772714/edittext-loses-content-on-scroll-in-listview?rq=1 – JahShaka
你是怎么解决问题#3?如果解决了,请发表回答 – desidigitalnomad