读取条形码时,Listview项目数据重复

时间:2018-11-02 06:25:46

标签: android android-studio 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);

}

}

0 个答案:

没有答案