首页 > 解决方案 > 当我阅读条形码时,Listview 项目数据重复

问题描述

我有一个应用程序,我可以在其中打开相机并读取条形码。我在 listview 项目中显示条形码。当我读取它添加到所有 listview 项目的条形码时。它重复。我尝试其他解决方案,如 ViewHolder,但它不起作用在我的代码中。我该如何解决这个问题???

//我添加了调用条码

 @Override
 public View getGroupView(int groupPosition, boolean isExpanded, View 
 convertView, ViewGroup parent) {
    SubeUrunListesiBaslik urunBaslik = (SubeUrunListesiBaslik) getGroup(groupPosition);

    if (convertView == null) {

        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_group, null);

    }
 @Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    try {
        final int fnlgrppos = groupPosition;
        final int fnlcldpos = childPosition;
        final UrunBakimGuncellemeDetay childinfo = (UrunBakimGuncellemeDetay) getChild(groupPosition, childPosition);

        if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         convertView = inflater.inflate(R.layout.list_item, null);


            }
    final View fv = convertView;
        imbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent barcodeReaderIntent = new Intent(context, BarcodeReader.class);
                ArrayList<KeyValueListType> barkodList = new ArrayList<>();
                ListView lvBarkod = (ListView)fv.findViewById(R.id.lvBakimGirisBarkodList);
                for (int i=0; i<lvBarkod.getCount();i++){
                    KeyValueListType kvlt = (KeyValueListType) lvBarkod.getItemAtPosition(i);
                    barkodList.add(kvlt);
                }
                ComplexParameterPass.CHILD_POSITION = fnlcldpos;
                ComplexParameterPass.GROUP_POSITION = fnlgrppos;
                ComplexParameterPass.lvParam = barkodList;
                try {
                    getActivity(context).startActivityForResult(barcodeReaderIntent, ComplexParameterPass.REQUEST_CODE_GUNCELLEME_BARCODE);
                }catch (Exception ex){
                    ex.printStackTrace();
                }
            }



      });
  // I put in here
       if (childinfo.barkodList != null) {

          ListView lvBarkodListesi = (ListView) 
               convertView.findViewById(R.id.lvBakimGirisBarkodList);
          ArrayAdapter adapter = new ArrayAdapter(context, 
           android.R.layout.simple_list_item_1,childinfo.barkodList);
            lvBarkodListesi.setAdapter(adapter);


      }

//条码

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ComplexParameterPass.REQUEST_CODE_GUNCELLEME_BARCODE) {
        List<UrunBakimGuncellemeDetay> urunBakimGuncellemeDetayList = 

       ComplexParameterPass.listHash.get(ComplexParameterPass
      .headerList.get(ComplexParameterPass.GROUP_POSITION).serino);
        urunBakimGuncellemeDetayList.get(0).barkodList = ComplexParameterPass.lvParam;

    }

    ExpandableListView lvUrunler = (ExpandableListView)findViewById(R.id.lvSubeIslemleriUrunListesi);
    ExpandableListAdapter listAdapter;
    listAdapter = new SubeExpandableListAdapter (this, ComplexParameterPass.headerList, ComplexParameterPass.listHash);
    lvUrunler.setAdapter(listAdapter);

    if (ComplexParameterPass.GROUP_POSITION != -1) {
        lvUrunler.expandGroup(ComplexParameterPass.GROUP_POSITION);
        lvUrunler.setSelectedGroup(ComplexParameterPass.GROUP_POSITION);

}

}

标签: androidandroid-studiolistview

解决方案


推荐阅读