我遇到了问题我无法解决。谢谢你的帮助。
我尝试删除SwipeMenuListView
上的某个项目但我不能这样做。
这是我的代码;
list= (SwipeMenuListView) findViewById(R.id.listView1);
groups = new UserData(getApplication()).getUserGroups();
if (groups == null)
groups = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, groups.toArray(new String[0]));
list.setAdapter(adapter);
list.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
switch (index) {
case 0:
try {
groups.remove(position);
adapter.notifyDataSetChanged();
Log.d("TAG","onMenuClickListener"+index+" position is "+ position);
break;
}
catch (Exception e) {
Log.d("TAG","error " + e);
}
}
// false : close the menu; true : not close the menu
return false;
}
});
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent intent = new Intent(GroupActivity.this, MapsActivity.class);
intent.putExtra("GRUPID", groups.get(position));
startActivity(intent);
}
});
当我尝试删除项目时,项目未删除,第二次按下按钮时发生错误;
java.lang.IndexOutOfBoundsException:索引1无效,大小为1.
我认为该项目已删除但仍会显示。
再次感谢您的帮助。