我正在使用gridview布局显示多个项目,并且项目显示良好,如果我在大屏幕上进行检查,则所有工作都很好,因为不需要滚动。 但是,如果我在滚动时使用小屏幕,则会动态更改位置。 **示例:** 如果我显示50个项目,那么如果我显示1000个需要向下滚动的项目,则工作正常,这时所选项目正在动态更改其位置。
适配器代码
public class EM_event_total_userseatsAdapter extends ArrayAdapter<EM_event_total_UserSeatsModel> implements View.OnClickListener {
ArrayList<EM_event_total_UserSeatsModel> dataSet;
public ArrayList<Integer> EMeventuserseatslist = new ArrayList<Integer>();
Context mContext;
ViewHolder holder;
String user_seats;
private int[] tagCollection;
private String[] mobileValues;
private String[] mobileValuesD;
private static class ViewHolder {
TextView TvEmUserSeats;
ImageView IvUsreSeats,available,selctedimag;
}
private String[] strings;
List<Integer> selectedPositions = new ArrayList<>();
SparseBooleanArray selectedItems;
public
EM_event_total_userseatsAdapter(ArrayList<EM_event_total_UserSeatsModel> data, Context context) {
super(context, R.layout.list_em_get_seats, data);
this.dataSet = data;
this.mContext=context;
selectedItems = new SparseBooleanArray();
}
public int getTagFromPosition(int position) {
return tagCollection[position];
}
@Override
public void onClick(View v) {
int position=(Integer) v.getTag();
Object object= getItem(tagCollection[position]);
EM_event_total_UserSeatsModel dataModel=(EM_event_total_UserSeatsModel)
object;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
EM_event_total_UserSeatsModel 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.list_em_get_seats, parent, false);
viewHolder.TvEmUserSeats = (TextView) convertView.findViewById(R.id.TvEmUserSeats);
viewHolder.IvUsreSeats = (ImageView) convertView.findViewById(R.id.IvUsreSeats);
result=convertView;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
result=convertView;
}
String blue_available = "seat3.png";
String red_booked = "seat1.png";
String get_seat = dataModel.getBookedStatus();
viewHolder.TvEmUserSeats.setText(dataModel.getSeatName());
//holder.imgSeatSelected.setVisibility(isSelected(position) ? View.VISIBLE : View.INVISIBLE);
if(Integer.parseInt(get_seat) == 1){
Picasso.with(mContext).load(main_url+"assets/admin/img/" + red_booked).into(viewHolder.IvUsreSeats);
}else
{
Picasso.with(mContext).load(main_url+"assets/admin/img/" + blue_available).into(viewHolder.IvUsreSeats);
}
return convertView;
}
public void toggleSelection(int position) {
if (selectedItems.get(position, false)) {
selectedItems.delete(position);
} else {
selectedItems.put(position, true);
}
notifyDataSetChanged();
}
public void clearSelections() {
selectedItems.clear();
notifyDataSetChanged();
}
public int getSelectedItemCount() {
return selectedItems.size();
}
public String getSelectedItems() {
String items = "";
for (int i = 0; i < selectedItems.size(); i++) {
items += selectedItems.keyAt(i);
}
return items;
}
}