Alex Rivera | Logout

removeView(View) is not supported in AdapterView

Asked 2012-07-11T08:03:25.847
11

I want to delete a certain row from a listView when an ImageView is clicked. My listview looks like this : enter image description here

I want that when the last image is clicked to delete that row. Here is my adapter :

public class UserItemAdapter extends ArrayAdapter<Photos.Record> {
        private ArrayList<Photos.Record> photos;

        public UserItemAdapter(Context context, int textViewResourceId, ArrayList<Photos.Record> photos) {
            super(context, textViewResourceId, photos);
            this.photos = photos;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View v = convertView;


            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.photorowlist, null);
                                v.setClickable(true);
                                v.setFocusable(true);
            }

            Photos.Record user = photos.get(position);
            if (user != null) {
                TextView photo_name = (TextView) v.findViewById(R.id.photoname);

                if (photo_name != null) {
                    photo_name.setText(user.photo_name);
                }

            }
                        v.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            //Toast.makeText(view.getContext(), "Clicked", Toast.LENGTH_SHORT).show();

                            ImageView delete_photo = (ImageView) view.findViewById(R.id.deletephoto);
                            delete_photo.setOnClickListener(new OnClickListener(){  
                            @Override  
                            public void onClick(View v) {  
                                Toast.makeText(Pho
Edit
Report

1 Answer

0

You should try it on the UI thread so that it works instantaneously:

     listView.remove(position);
        runOnUiThread(new Runnable() {
            public void run() {
                adapter.notifyDataSetChanged();
            }
        });
answered 2012-07-11T08:43:28.507

Your Answer