我试图在我的测试项目中使用ListViewAnimations library
,我有一个活动,我想在此列表中实现药物和丢弃功能
我的 ListViewTest:
public class ListViewTest extends ActionBarActivity {
DynamicListView list;
DataBaseAdapter dataBaseHelper;
private int mNewItemCount;
public List<Cards> list1;
Cards cards;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view_test);
dataBaseHelper = new DataBaseAdapter(this);
MyAdapter adapter1 = new MyAdapter(this, dataBaseHelper.getData());
list = (DynamicListView) findViewById(R.id.test_list_view);
list.enableDragAndDrop();
list.setDraggableManager(new TouchViewDraggableManager(R.id.linear_layout));
list.setOnItemMovedListener(new MyOnItemMovedListener(adapter1, list1));
list.setOnItemLongClickListener(new MyOnItemLongClickListener(list));
list.setAdapter(adapter1);
}
private static class MyOnItemLongClickListener implements AdapterView.OnItemLongClickListener {
private final DynamicListView mListView;
MyOnItemLongClickListener(final DynamicListView listView) {
mListView = listView;
}
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) {
return true;
}
}
private class MyOnDismissCallback implements OnDismissCallback {
private final MyAdapter myAdapter;
@Nullable
private Toast mToast;
MyOnDismissCallback(final MyAdapter adapt) {
myAdapter = adapt;
}
@Override
public void onDismiss(@NonNull final ViewGroup listView, @NonNull final int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
myAdapter.remove(position);
}
if (mToast != null) {
mToast.cancel();
}
}
}
private class MyOnItemMovedListener implements OnItemMovedListener {
private final MyAdapter adapter1;
List<Cards> cardsList;
private Toast mToast;
MyOnItemMovedListener(final MyAdapter adapt, List<Cards> list1) {
adapter1 = adapt;
cardsList = list1;
}
@Override
public void onItemMoved(final int originalPosition, final int newPosition) {
}
}
private class MyOnItemClickListener implements AdapterView.OnItemClickListener {
private final DynamicListView mListView;
MyOnItemClickListener(final DynamicListView listView) {
mListView = listView;
}
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
mListView.insert(position, mNewItemCount);
mNewItemCount++;
}
}
}
MyAdapter类:
public class MyAdapter extends ArrayAdapter<Cards> {
private Activity mActivity;
private List<Cards> data;
public static LayoutInflater inflater = null;
public Resources resources;
Cards cards = null;
int i = 0;
private final Context mContext;
public MyAdapter(final Context context, List d) {
mContext = context;
this.data = d;
}
public static class ViewHolder {
public TextView text;
public ImageView image;
}
@Override
public View getView(final int position,final View convertView,final ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
if(convertView == null){
vi =(View) LayoutInflater.from(mContext).inflate(R.layout.custom_row, parent, false);
holder = new ViewHolder();
holder.text = (TextView)vi.findViewById(R.id.listText);
holder.image = (ImageView) vi.findViewById(R.id.image_country);
vi.setTag(holder);
}else
holder = (ViewHolder) vi.getTag();
if(data.size()<=0){
}
else {
cards = data.get(position);
holder.text.setText(cards.getName());
}
return vi;
}
@Override
public long getItemId(int position) {
return position;
}
@NonNull
@Override
public List<Cards> getItems() {
return super.getItems();
}
@Override
public int getCount() {
if (data.size() <= 0)
return 1;
return data.size();
}
@Override
public boolean hasStableIds() {
return true;
}
}
卡是我的getter和setter类,列表是填充舞会SQlite db,当我的程序启动它一切正常,但当我尝试吸毒和丢弃物品时,我有:{{1 }。我感觉我没有在java.lang.IndexOutOfBoundsException: Invalid index (here is current item index), size is 0
中宣布我的名单,但我没弄明白该怎么做以及如何重写我的名单
感谢您的回答