先来几张图
下面的要添加的代码:
对list.setOnItemClickListener(new ListOnItemClickListener());
private class ListOnItemClickListener implements OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
CATEGORYTWO categorytwo=categorieList.get(position);
fenleiAdapter.setSelectIndex(position);
fenleiAdapter.notifyDataSetChanged();
}
}
在自定义的adapter中
private int selectIndex = -1;属性
public void setSelectIndex(int i){
selectIndex = i;
}
在getview中
if(position == selectIndex){
holder.layout.setBackground(mContext.getResources()
.getDrawable(R.drawable.category_new_left_facous));
holder.categroyTitle.setTextColor(mContext.getResources().getColor(
R.color.category_new_red_font));
}else{
holder.categroyTitle.setTextColor(mContext.getResources().getColor(
R.color.category_new__dark_font));
holder.layout.setBackground(mContext.getResources()
.getDrawable(R.drawable.category_new_left_normal));
}
holder.layout是XML中的布局
holder.categroyTitle----一个textview