Hi, I am new to Android programming and need help with onItemLongClick.
I have implemented an OnItemLongClickListener but when i long click on an item in my list an UnsupportedOperationException is raised. I include two files below listmodified and my custom adapter CustomAdapter Thanks in advance, listmodified.class * package *listmodified.org; * import *java.util.Arrays;* import *java.util.ArrayList;* import *android.app.ListActivity;* import *android.os.Bundle;* import *android.view.View;* import *android.widget.AdapterView;* import *android.widget.ArrayAdapter;* import *android.widget.ListView;* import *android.widget.TextView;* import *android.widget.AdapterView.OnItemLongClickListener; * public **class* listmodified *extends* ListActivity { *private* TextView selection; // MAIN.xml ArrayAdapter<String> adapter; // for accessing my adapter *private* String itemSelected; // for delete function *public* *static* String[] *items*={"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam", "vel", "erat", "placerat", "ante", "porttitor", "sodales", "pellentesque", "augue", "purus"}; @Override *public* *void* onCreate(Bundle icicle) { *super*.onCreate(icicle); //onLongClick must be activity and imported above OnItemLongClickListener itemDelListener = *new* OnItemLongClickListener(){ @Override *public* *boolean* onItemLongClick(AdapterView<?> parent, View arg1, *int* position, *long* arg3) { // *TODO* Auto-generated method stub itemSelected=parent.getItemAtPosition(position).toString(); adapter.remove(itemSelected); adapter.notifyDataSetChanged(); *return* *false*; }}; setContentView(R.layout. *main*); adapter=*new* CustomAdapter(listmodified.*this*, R.layout.*row*, *items*); setListAdapter( adapter); selection=(TextView)findViewById(R.id.*selection*); getListView().setOnItemLongClickListener(itemDelListener); } *public* *void* onListItemClick(ListView parent, View v, *int* position, *long* id) { selection.setText(*items*[position]); } } //// * mport **java.util.ArrayList*; * import **android.app.ListActivity*;* import *android.content.Context;* import **android.os.Bundle*;* import *android.view.LayoutInflater;* import *android.view.View;* import *android.view.ViewGroup;* import *android.widget.ArrayAdapter;* import *android.widget.ImageView;* import **android.widget.ListView*;* import *android.widget.TextView;* import **android.widget.Toast*; * public **class* CustomAdapter *extends* ArrayAdapter<String>{ LayoutInflater inflater; *public* CustomAdapter(Context context, *int* textViewResourceId, String[] objects) { *super*(context, textViewResourceId, objects); Context *myContext* = context; // *TODO* Auto-generated constructor stub } //override default view create my own unique view *public* View getView(*int* position, View convertView, ViewGroup parent){ View row=convertView; *if*(row==*null*){ //not sure about the following line of code, something to do with context LayoutInflater inflater=LayoutInflater.*from*(getContext()); row=inflater.inflate(R.layout. *row*, *null*); } TextView label=(TextView)row.findViewById(R.id. *weekofday*); label.setText(listmodified. *items*[position]); ImageView icon=(ImageView)row.findViewById(R.id. *icon*); *if*(listmodified.*items*[position].length()<=1){ icon=(ImageView)row.findViewById(R.id. *icon*); icon.setImageResource(R.drawable. *small_x_dark*); } *else*{ icon.setImageResource(R.drawable. *ok*); } *return* row; //This function must return something } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en