我TextView
在实时更新 a 时遇到问题。我想用自定义适配器实时更新TextView
a 。ListView
我有接收 JSON 消息的套接字 I/O 处理程序。我想解析这个 JSON 并将该文本放入特定的列表行中setText()
。如何获取该ListView
行的索引并更新其TextView
?
responseid=object.getString("ResponseID");
if(responseid!=null){
for(int j=0;j<countryList.size();j++){
//If the countryList row match then i want to update the textView of that particular row
if(countryList.get(j).getName().equals(caseid)) {
int oldcount = Integer.parseInt((dataAdapter.findViewById(R.id.replycount)).getText().toString());
int total=oldcount+1;
(dataAdapter.findViewById(R.id.replycount)).setText(Integer.toString(total));
dataAdapter.notifyDataSetChanged();
}
}
}
这是我的解决方案:
for(int j=0;j<countryList.size();j++)
{
if(countryList.get(j).getName().equals(caseid))
{
String oldcount = countryList.get(j).getCount();
int oldcountint = Integer.parseInt(oldcount);
int newcount = oldcountint + 1;
countryList.get(j).setCount(Integer.toString(newcount));
dataAdapter.notifyDataSetChanged();
break;
}
}