gpt4 book ai didi

java - ListView 的单个项目未更新

转载 作者:行者123 更新时间:2023-12-02 12:10:35 26 4
gpt4 key购买 nike

在这里,我的 listView 现在有 2 个项目,如下图所示

enter image description here

这是用于ListViewSimpleAdapter

           ListView listProductSup;
int listItemPos;
SimpleAdapter pdtAdapter;
pdtAdapter = new SimpleAdapter(
ProductProgramActivity.this, pdtDataList,
R.layout.product_supp_list, new String[]{"pdtSupName", "strKey", "strServQuan", "strMilkQuan", "strWaterQuan", "strDecocQuan", "strPowderQuan"},
new int[]{R.id.txt_list_pdt_supp, R.id.key_set, R.id.serve_quan_set, R.id.milk_quan_set, R.id.wat_quan_set, R.id.decoc_quan_set, R.id.pow_quan_set});
listProductSup.setAdapter(pdtAdapter);
listProductSup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in = null;
listItemPos = position;
if (categIn.equals("Machine Installation"))
in = new Intent(ProductProgramActivity.this, ProgramSettingActivity.class);
else if (categIn.equals("Machine Disconnection"))
in = new Intent(ProductProgramActivity.this, MachineDisconActivity.class);
in.putExtra("idOfIncident", idOfIncident);
in.putExtra("orgId", orgId);
in.putExtra("assetId", assetId);
in.putExtra("pdtId", pdtIdArr.get(position));
in.putExtra("pdtSupId", pdtSupIdArr.get(position));
startActivityForResult(in,1);
}
});

单击列表项后,它将转到下一个 Activity 。我正在从该 Activity 中的 textFields 获取所有值。从那里onBackPressed我将发回所有分配的值,如下所示

public void backWithData() {
Intent in = new Intent();
in.putExtra("pdtSupId", pdtSupId);
in.putExtra("strKey", strKey);
in.putExtra("strServQuan", strServQuan);
in.putExtra("strMilkQuan", strMilkQuan);
in.putExtra("strWaterQuan", strWaterQuan);
in.putExtra("strDecocQuan", strDecocQuan);
in.putExtra("strPowderQuan", strPowderQuan);
setResult(RESULT_OK, in);
}
@Override
public void onBackPressed() {
backWithData();
finish();
}

在上一个 Activity 中,我再次通过重写 onActivityResult 来获取所有值。

在这里,我尝试更新单击以提供所有值的 ListView 的单个项目。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if(resultCode == RESULT_OK) {
pdtSupId = data.getStringExtra("pdtSupId");
strKey = data.getStringExtra("strKey");
strServQuan = data.getStringExtra("strServQuan");
strMilkQuan = data.getStringExtra("strMilkQuan");
strWaterQuan = data.getStringExtra("strWaterQuan");
strDecocQuan = data.getStringExtra("strDecocQuan");
strPowderQuan = data.getStringExtra("strPowderQuan");
int first = listProductSup.getFirstVisiblePosition();
int last = listProductSup.getLastVisiblePosition();
for (int i=0; i<=pdtDataList.size(); i++)
if (pdtSupIdArr.get(i).equals(pdtSupId))
if (i == listItemPos) {
View view = listProductSup.getChildAt(i);
listProductSup.getAdapter().getView(i, view, listProductSup);
((TextView)view.findViewById(R.id.key_set)).setText(strKey);
((TextView)view.findViewById(R.id.serve_quan_set)).setText(strServQuan);
((TextView)view.findViewById(R.id.milk_quan_set)).setText(strMilkQuan);
((TextView)view.findViewById(R.id.wat_quan_set)).setText(strWaterQuan);
((TextView)view.findViewById(R.id.decoc_quan_set)).setText(strDecocQuan);
((TextView)view.findViewById(R.id.pow_quan_set)).setText(strPowderQuan);
break;
}
pdtAdapter.notifyDataSetChanged();
}
}
}

但我不知道为什么它没有更新。

为了更新ListView的单个项目,我引用了SO的其他答案。喜欢Answer 1以及其他答案。

最佳答案

Hi 更新列表 onActivity 结果中的相应对象然后调用 notificationDatasetChanged() ,它会自动更新 ui...

关于java - ListView 的单个项目未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46581152/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com