hanry what errors do you get? I implemented it and it works correctly. But instead of preserving the position of the element, I save the view holder, which among others also has a model property. Remember that you need to check if the conversion is null. Take a look at the code:
public View getView(int position, View convertView, ViewGroup parent) { View view = null; Model m = filter.subItems.get(position); if(m != null) { if (convertView == null) { LayoutInflater inflator = context.getLayoutInflater(); view = inflator.inflate(R.layout.rowlayout, null); ViewHolder viewHolder = new ViewHolder(); viewHolder.position = position; - here you can put your position. view.setOnTouchListener(this.listener);
and then
public boolean onTouch(View v, MotionEvent event) { ViewHolder viewHolder = ((ViewHolder) v.getTag()); }
hop that helps. ps: If you know nothing about the holders and tags to view, I come to there . And my approach was described in the link that Frankenstein gave.
source share