我一直在做一个涉及使用Web服务的项目。我有一个产品列表,将在UI中显示为图像,按钮喜欢,添加到列表和其他一些。我已经在自定义列表视图中实现了这些项目,并像往常一样在适配器类中添加了产品。如果我为某个图像选择一个"喜欢"按钮,那么该按钮应该更改为"不喜欢",我在这里面临的问题是所有项目的按钮都会更改,即列表视图中的所有按钮都更改为"喜欢"这是愚蠢的。
问题:
如何查明要更改的某个列表项(或)如何更改列表中的单个按钮?
我在这里缺乏逻辑。任何帮助将不胜感激。
没有代码很难具体提供帮助,但是您是否尝试过使用类似的东西,
listview.getChildAt(position);
以引用特定列表项。
根据您的代码,您可以修改以下内容:
yourlistview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
//on click of any item.
Toast.makeText(getApplicationContext(), "Your position"+position, Toast.LENGTH_LONG).show();
//This is just for example to obtain the position of the listview item.
TextView example= (TextView)findViewById(R.id.sometext);
example.setText(String.valueOf(position));
}
});
希望这能给你一些信息..:)