Custom ArrayAdapter onLongClickListener

880 Views Asked by At

Hey Guys I have the following problem, I made a ListView with an Custom ArrayAdapter for it . Now I want to define a onLongClickListener inside the ArrayAdapter, but I get the wrong Item everytime. Everytime I get the Item that was deleted, so if i have an string array with the values: one,two,three,four,five,six etc and I can see 4 ListView Items(the first 4) I get the value: five

does anybody know how to solve that issue?

   public View getView(int position, View rowView, ViewGroup parent) {
            this.position=position;
            rowView = inflater.inflate(R.layout.task_item, null, true);
            holder = new ViewHolder();
            holder.text = (TextView) rowView.findViewById(R.id.task_item);
            holder.img=(ImageView) rowView.findViewById(R.id.task_item_rating);
            holder.text.setText(objects[position].toString());
            holder.text.setGravity(Gravity.CENTER_HORIZONTAL);
            holder.text.setPadding(0, 20, 0, 20);
            rowView.setTag(holder);
            rowView.setOnLongClickListener(myLong);
            return rowView;
    }


    public OnLongClickListener myLong = new OnLongClickListener() {
        public boolean onLongClick(View v) {
            //do something
        }
    }
1

There are 1 best solutions below

0
On

-i think you must use arrayadapter.notifyDataSetChanged(); after removing the item with -arrayadapter.remove(index); //this is the adapter that you will bind to listview -use on listView.setOnItemLongClickListener(). instead of