初学者 android 程序员,我想在用户单击 listitem 时从字符串列表中添加和删除项目,但是在尝试执行此操作时出现操作不支持错误。请参阅以下代码以了解我想要做什么。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if(myList != null)
{
StringBuilder stringBuilder = new StringBuilder();
if(myList.contains(mylist1.get(position).getPackageName()))
{
for(int i = 0; i < myList.size(); i++)
{
if(myList.get(i).equals(mylist1.get(position).getPackageName()))
continue;
if((myList.size() - 1) != i)
stringBuilder.append(myList.get(i)).append(separator);
else
stringBuilder.append(myList.get(i));
}
editor.putString("mypreference", stringBuilder.toString());
mylistt1.get(position).setDisabled(false);
//error happens in following
myList.remove(mylist1.get(position).getPackageName());
}
}
}
这是日志猫
04-08 11:33:00.030: ERROR/AndroidRuntime(533): FATAL EXCEPTION: main
java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:638)
at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:75)
at java.util.AbstractCollection.remove(AbstractCollection.java:229)
at com.mypackage.myActivity.onListItemClick(myActivity.java:82)
at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
at android.widget.AbsListView$1.run(AbsListView.java:3168)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)