久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

列表視圖中的 EditText 重復值

EditText in listview repeats the value(列表視圖中的 EditText 重復值)
本文介紹了列表視圖中的 EditText 重復值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

列表中有三個文本視圖和一個編輯文本.當我在編輯文本中輸入任何值時,相同的值也會復制到另一個編輯文本中.我厭倦了同時使用 onFocusChangedListener 和 onTextChanged 實現,但兩種情況下的問題都是一樣的.

I have three textviews and one edit text in the list. when I entered any value in the edittext, the same value is also copied in the other edittext. I tired implementing with both onFocusChangedListener and onTextChanged but the problem is same in both the cases.

public class ProductListAdapter extends BaseAdapter {

Context context;
public ArrayList<Products> prodList;
private static LayoutInflater inflater = null;
public ProductsList productListActivity;

public ProductListAdapter(Context context,ArrayList<Products> prodList) {
    this.context = context;
    this.prodList = prodList;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Log.e("In adapter", "yes");
}

@Override
public int getCount() {
    return prodList.size();
}

@Override
public Products getItem(int position) {
     return prodList.get(position); }

@Override
public long getItemId(int position) {
    return position;
}
@Override
public View getView( final int position, View convertView, ViewGroup parent) {
      Log.i(" in prodlist adapter","View holder");
      final   ViewHolder holder;
      if (convertView == null) {
            convertView = inflater.inflate(R.layout.productslistviewadapter, parent, false);

            holder = new ViewHolder();
            holder.tvdrCode = (TextView) convertView.findViewById(R.id.tvname);
            holder.tvDrName = (TextView) convertView.findViewById(R.id.tvprodpack);
            holder.tvterrcode= (TextView) convertView.findViewById(R.id.textView3);
            holder.caption = (EditText)convertView.findViewById(R.id.editText1);
            convertView.setTag(holder);

        } 
     else {
            holder = (ViewHolder) convertView.getTag();
        }

        Products p = prodList.get(position);
        holder.tvdrCode.setText(p.getDocCode());
        holder.tvDrName.setText(p.getDocName());
        holder.tvterrcode.setText(p.getAdr());

        //holder.caption.setText(prodList.get(position).caption);
       /* holder.caption.setId(position);

        holder.caption.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
               if (!hasFocus) {
                    final int position = v.getId();
                    final EditText Caption = (EditText) v;  
                //  prodList.get(position)= Caption.getText().toString();
                    String d = prodList.get(position).getDocCode();
                    Log.e("dr code",d);
                }
            }
        }); */          

        holder.caption.setTag(position);
        // holder.caption.setText(ProdList.get(position).toString());
        int tag_position=(Integer) holder.caption.getTag();
        holder.caption.setId(tag_position); 

        holder.caption.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start,int before, int count) {
                  //2nd method  String d = planArraylist.get(position).getDocCode();
                 final int position2 = holder.caption.getId();
                 final EditText Caption = (EditText) holder.caption;
                 if(Caption.getText().toString().length()>0){
                    String d = prodList.get(position2).getDocCode();
                    Log.e("dr code",d);

                 }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start,
                    int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });  
            return convertView;
} 

 static class ViewHolder {
     TextView tvdrCode;
     TextView tvDrName;
     TextView tvterrcode;
     EditText caption;

} 
}

xml代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:animationCache="false"
    android:scrollingCache="false"
    android:smoothScrollbar="true" > 

<!--    android:descendantFocusability="beforeDescendants" -->

</ListView>

推薦答案

我們知道 ListView 在滾動整個列表時會重用 ListItem 的視圖.

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

所以當我們有一個帶有 EditText 的自定義 ListView 時就會出現問題,如果我們在第一個 EditText 中輸入任何值并開始滾動,那么當我們滾動 listview 時,一個 EditText 的值會被一個一個地復制到另一個 EditTexts 中.

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.

http://www.webplusandroid.com/creating-listview-with-edittext-and-textwatcher-in-android/

這篇關于列表視圖中的 EditText 重復值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 久久久妇女国产精品影视 | 免费看啪啪网站 | 日本视频免费 | 精品国产视频 | 激情国产 | 美女视频一区 | 色婷婷一区二区三区四区 | 成人在线观看亚洲 | 性高朝久久久久久久3小时 av一区二区三区四区 | 99国产精品99久久久久久粉嫩 | 国产日产精品一区二区三区四区 | 欧美日本一区 | 久久久久久久一区二区 | av在线免费不卡 | 奇米影视77 | 亚洲成av人片在线观看无码 | 免费黄色在线观看 | 国产亚洲成av人片在线观看桃 | 日本精品久久 | 国产精品明星裸体写真集 | 韩国av电影网 | 国产成人精品视频 | a爱视频| 日本三级在线网站 | 国产精品一区久久久 | 365夜爽爽欧美性午夜免费视频 | 在线日韩视频 | 91伦理片 | 韩国精品一区 | 日韩喷潮 | 日日日日日日bbbbb视频 | 一本大道久久a久久精二百 欧洲一区二区三区 | 国产精品久久久久久久久免费樱桃 | 久久艹av| 精品久久久久一区二区国产 | 在线精品亚洲欧美日韩国产 | 日一区二区 | 在线一区二区三区 | 亚洲精品一区在线观看 | 亚洲免费在线 | 国产精品国产精品国产专区不卡 |