ArrayList
。添加
isSelected
private boolean isSelected;
public boolean isSelected() {
return isSelected;
}
public void setIsSelected(boolean isSelected) {
isSelected = isSelected;
}
Java
YOUR_ARRAYLIST.get(POSITION_WHICH_U_WANT_TO_SELECT).setIsSelected(true);
在里面
getView
方法,你需要检查视图是否正确
挑选出来的
或
未选定
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
ModifierSet dataModel = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
ViewHolder viewHolder; // view lookup cache stored in tag
final View result;
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.row_item, parent, false);
result=convertView;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
result=convertView;
}
if(dataModel.get(position).isSelected())
{
/**
* SET THE LISTVIEW'S ITEM SELECTED HERE
*/
}
else
{
/**
* SET THE LISTVIEW'S ITEM UN-SELECTED HERE
*/
}
}