-2

当我单击喜欢按钮时,我在每个列表项中都有喜欢按钮,我正在调用服务以将数据推送到服务器,最后根据响应我想更改按钮。我正在使用下面的代码进行更改

在活动课上

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");
    }

当我更新数据时,我得到列表视图项的空值。如果有人知道请帮助我。

4

2 回答 2

0

您是否尝试过 AdapterView.OnItemClickListener?

http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html

onItemClick(AdapterView<?> parent, View view, int position, long id) 

view是被点击的列表项,所以如果你想改变它,你可以改变view参数。

于 2013-07-16T17:30:23.707 回答
0

最后我在调用 notifyDataSetChanged() 之后通过更新数组列表得到我的解决方案

    map.put("like",  increament by previous value);
    arrlist.set(listItemPosition, map);
    notifyDataSetChanged();
于 2013-07-22T12:16:12.383 回答