如何在Android中更改列表项的背景颜色?
作者:互联网
如何更改android中列表项的长按背景颜色,现在通过使用下面的代码获取列表项的位置onlongclick.
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
// TODO Auto-generated method stub
Log.v("long clicked","pos: " + pos);
return true;
}
});
任何帮助都会受到赞赏,谢谢
解决方法:
试试这个,
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int arg2, long arg3) {
view.setBackgroundColor(Color.parseColor("#222222"));
Log.v("Long Click", "Working");
return false;
}
});
标签:android,listview,long-click 来源: https://codeday.me/bug/20190831/1775456.html