zoukankan      html  css  js  c++  java
  • listView获取item的Edit内容,listView中的edit内容在滚动时自动赋值了前面的内容

    Today I am going to explain how to create a ListView with EditText and why will we need a TextWatcher to implement the same.

    Before starting the topic, let us know why this topic is necessary.

    Issue:

    As we know ListView reuses the view of  ListItem as we scroll the whole list.

    So problem arises when we have a custom  ListView with  EditText where if we enter any value in the first EditText and start scrolling then the value of EditText one is copied to another the EditTexts one by one as we scroll the listview .

    This happens as the listview reuses the view and as the other listitem from another view i.e. the view which is not seen scrolls upwards it reuses the old lists view and hence the old value of that view is seen in the new edittext.

    The issue can be seen it the below image:

    device-2014-08-03-181411

    Now Scroll the List:

    device-2014-08-03-181457

    From above we can see that Text1 EdiText data is copied to Text10 and so on and so forth. The above issue can be resolved and the code to resolve the above issue is as follows:

    First create your parent ListView layout:

    lyt_listview_activity.xml

    Then Create ListItem which will be your listview items:

    lyt_listview_list.xml

    Now this will be your Activity code:

    ListviewActivity.java

    This will be your manisfest file: Notice the tag windowSoftInputMode=”adjustPan” this will resolve keyboard focus issue in editText in listview

    AndroidManifest.xml

    In above activity code the TextWatcher code handles the issue of duplicating of one editText value to other. This will happen using a temporary  variable which will store the previous value of editText with respect to its position and will set it when the same editText comes into focus or view.

    Please comment if you have any doubts or any other issue. I will be happy to help…

  • 相关阅读:
    vs已停止工作
    2.3.4 工具运行和错误解决方法
    vs2010 :0X80041FEB 程序集无法修改版等内容
    VS2010 F5调试时出现:“ 尝试运行项目时出错:未捕获通过反射调用的方法引发的异常”解决
    栅格计算器中空间分析函数
    设备系统,个人消费系统
    知己知彼
    ASP.NET MVC 实现二级域名
    自定义ASP.NET MVC Html辅助方法
    MVC系统过滤器(局部缓存,局部动态)
  • 原文地址:https://www.cnblogs.com/zmc/p/5568303.html
Copyright © 2011-2022 走看看