滚动后,SwipeMenuListView中项目的位置会随机变化。列表视图中的项目也不可见,因为列表视图中仅显示项目5之前的项目。 这是我的代码:
public ArrayList<Item> initArrayList() {
ArrayList<Item> items = new ArrayList<>();
items.add(new Item("Item 1", "First Item on the list", "abc", "Item 1.4", "Item 1.5"));
items.add(new Item("Item 2", "Second Item on the list", "xyz", "item 2.4", "item 2.5"));
items.add(new Item("Item 3", "Third Item on the list", "qwe", "item 3.4", "item 3.5"));
items.add(new Item("Item 4", "Forth Item on the list", "qwe", "item 4.4", "item 4.5"));
items.add(new Item("Item 5", "Fifth Item on the list", "qwe", "item 5.4", "item 5.5"));
items.add(new Item("Item 6", "Sixth Item on the list", "qwe", "item 6.4", "item 6.5"));
items.add(new Item("Item 7", "Seventh Item on the list", "qwe", "item 7.4", "item 7.5"));
items.add(new Item("Item 8", "Eight Item on the list", "qwe", "item 8.4", "item 8.5"));
return items;
}
这是我的DataAdapter和Item类:
public class DataAdapter extends ArrayAdapter<Item> {
private final Context context;
private final ArrayList<Item> itemsArrayList;
public DataAdapter(Context context, ArrayList<Item> itemsArrayList) {
super(context, R.layout.list_item2, itemsArrayList);
this.context = context;
this.itemsArrayList = itemsArrayList;
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// 1. Create inflater
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// 2. Get rowView from inflater
View rowView = inflater.inflate(R.layout.list_item2, parent, false);
// 3. Get the two text view from the rowView
TextView tv1 = (TextView) rowView.findViewById(R.id.tv1);
TextView tv2 = (TextView) rowView.findViewById(R.id.tv2);
TextView tv3 = (TextView) rowView.findViewById(R.id.tv3);
TextView tv4 = (TextView) rowView.findViewById(R.id.tv4);
TextView tv5 = (TextView) rowView.findViewById(R.id.tv5);
// 4. Set the text for textView
tv1.setText(itemsArrayList.get(position).getTv1());
tv2.setText(itemsArrayList.get(position).getTv2());
tv3.setText(itemsArrayList.get(position).getTv3());
tv4.setText(itemsArrayList.get(position).getTv4());
tv5.setText(itemsArrayList.get(position).getTv5());
// 5. retrn rowView
return rowView;
}
这是mu Item类:
public class Item {
private String tv1;
private String tv2;
private String tv3;
private String tv4;
private String tv5;
public Item(String tv1, String tv2, String tv3,String tv4, String tv5) {
super();
this.tv1 = tv1;
this.tv2 = tv2;
this.tv3 = tv3;
this.tv4 = tv4;
this.tv5 = tv5;
}
public String getTv1(){
return tv1;
}
public String getTv2(){
return tv2;
}
public String getTv3(){
return tv3;
}
public String getTv4(){
return tv4;
}
public String getTv5(){
return tv5;
}