创建ListView的适配器ListViewAdapter继承BaseAdapter;在ListViewAdapter添加一个方法
public void setSelectPosition(int position){ this.mPosition = position;}
mPosition 在ListView的监听事件中传入。
lvLists.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { listsAdapter.setSelectPosition(position); listsAdapter.notifyDataSetChanged();}
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (mPosition == position){ convertView.setBackgroundColor(Color.WHITE); viewHolder.tvName.setTextColor(context.getResources().getColor(R.color.myColor)); }else { convertView.setBackgroundColor(context.getResources().getColor(R.color.myGrey)); viewHolder.tvName.setTextColor(Color.BLACK); } return convertView; }选中背景及文字颜色就会发生改变啦