java – Android:ListView中的EditText问题

java – Android:ListView中的EditText问题,第1张

概述我的应用程序中有一个列表视图,基本上是一个问题,所以有一些用户需要填写的EditText.我遇到了以下问题: >一些EditText需要数字输入,所以我将inputType设置为相应的xml类型为数字,但是,当我点击EditText时,数字键盘显示,但几乎立即消失,并显示常规键盘. >您可以想像,我需要存储用户在这些EditTexts中输入的值.我有这个问题是,在我输入一些文本在SOME Edit 我的应用程序中有一个列表视图,基本上是一个问题,所以有一些用户需要填写的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)

总结

以上是内存溢出为你收集整理的java – Android:ListView中的EditText问题全部内容,希望文章能够帮你解决java – Android:ListView中的EditText问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1148699.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存