大家好,又见面了,我是你们的朋友全栈君。
(1)listview item选择监听
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
adapter.setSelectItem(position);
adapter.notifyDataSetInvalidated();
}
});
(2)adaper
private class MyHouseSourceListAdapter extends BaseAdapter {
@Override
public int getCount() {
return houses.size();
}
@Override
public Object getItem(int position) {
return houses.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private int selectItem = -1;
private void setSelectItem(int selectItem){
this.selectItem = selectItem;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (null == convertView) {
viewHolder = new ViewHolder();
convertView = View.inflate(HouseSourceListPushActivity.this, R.layout.item_myhousesource, null);
//
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if(position == selectItem){
convertView.setBackgroundResource(R.color.mate_color);
}else{
convertView.setBackgroundResource(R.color.content_bg);
}
return convertView;
}
/**
* 房源的holder
*/
class ViewHolder {
ImageView fangyuan_image;
TextView fangyuan_Name;
TextView fangyuan_cishu;
TextView fangyuan_SuccessNum;
TextView fangyuan_prices;
TextView fangyuan_position;
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/160606.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...