当我单击喜欢按钮时,我在每个列表项中都有喜欢按钮,我正在调用服务以将数据推送到服务器,最后根据响应我想更改按钮。我正在使用下面的代码进行更改
在活动课上
CustomSimpleAdapter adapter = new CustomSimpleAdapter (
this, arr,
R.layout.listviewitem, new String[] {
"count", "likes"}, new int[] {
R.id.counttxt,
R.id.likes},list);
list.setAdapter(adapter);
在自定义 simpleAdater 类中
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
holder = new ViewHolder();
vi = inflater.inflate(R.layout.listviewitem, null);
holder.like = (TextView) vi.findViewById(R.id.like); // title
holder.count= (TextView) vi.findViewById(R.id.counttxt); // artist
vi.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.like.setId(position);
holder.like.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int listItemPosition = v.getId();
//calling web service here based on response i want to increase count size
if(respone.equal("success")
{
updatecount(listItemPosition );
}
}
});
private void updatecount(int index) {
View v = list.getChildAt(index - list.getFirstVisiblePosition());
someText1 = (TextView) v.findViewById(R.id.counttxt);//here i am getting null
int i = Integer.parseInt(data.get(index).get("Count"));
i++;
someText1.setText(Integer.toString(i) + "count");
}
当我更新数据时,我得到列表视图项的空值。如果有人知道请帮助我。