android - 当我阅读条形码时,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);
}
}
解决方案
推荐阅读
- python - 在 Windows 上的 input() 之前清除输入缓冲区?
- spring-boot-jpa - Spring Data 模块在自动配置期间在哪里寻找`@EnableJpaRepositotries` 和`@EntityScan` 注释?
- git - Apache Kafka 轮询是否比 gRPC 流或 HTTP 轮询更“有效”?
- conv-neural-network - 当我尝试拟合 CNN 模型时,收到 ValueError: Data cardinality is ambiguous:
- asp.net - docker build 失败,拒绝访问或存储库不存在
- c++ - 为什么在共享之前链接静态库时链接器不会删除未使用的符号?
- python - 如何检查 Kafka 中的分区数(confluent_kafka)
- node.js - Zetta 错误:请验证 package.json 是否具有有效的主条目
- php - 下载带有网页中显示的标签名称的 pdf 文件
- csv - 从 csv 到 HighCharts 散点图