关于改变ListView选中项的状态方法
思路:无论使用哪一个适配器,只需要重写他的getView()方法即可
原理:getView方法是用于把创建好的view交给listView用的,所以我们可以对创建好的view进行一个修改再交给ListView
例子:
public class MyListView extends ListView implements OnItemClickListener{
//用于记录点到了哪一个
private int mSelectPositon
public MyListView(Context context, AttributeSet attr){
super(context,attr);
this.setOnItemClickListener(this)
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
this.mSelectPosition = position;
}
class adapter extends ArrayAdapter{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView view = (TextView)super.getView(position, convertView, parent);
if(position == mSelectPosition){
view.textColor(Color.WHITE);
}else{
view.textColor(Color.BLACK);
}
return view;
}
}
}