Why does DynamicListview's dynamic drag and drop feature work with duplicates

I have been developing an android app so far. I want to add a DynamicListview drag and drop functionality to my ListView. I am following google tutorial and am using this tutorial code. I added this functionality successfully, but drap drop works in duplicate way, when I touch the listview items and drag it to another line, it creates other listview items again. When I drop my finger from the listview element it works correctly with the bud itself. The google tutorial works correctly and does not have this problem. To clear up my problem, I have added two videos. First, my video; drag and drop issue and google tutorial video well working (As you can see in the video, when I try to move the area, the area field is duplicated on every move, the google tutorial works well)

How can I fix this problem.

My codes are long, so I shared on the github gist;

Here's my DynamicListView class;

https://gist.github.com/salihyalcin/bd9a3c23179f44212419

Here's my NavigationDrawer class:

https://gist.github.com/salihyalcin/620467a96fdce3129d1b

Finally, my NavigationDrawerListViewAdapter:

https://gist.github.com/salihyalcin/474423f5705dbe41e8d6

+3


source to share


1 answer


I've looked at your code in the DynamicListView and NavigationDrawerListViewAdapter classes, mostly. As I said in my comments, I am familiar with the DynamicListView code and your code seems fine.

The problem I see is that yours originalItem

remains visible at the original (wrong) position, but inside the object (in the ArrayList object in the NavigationDrawerListViewAdapter) is no longer at the same position in the ArrayList. This is a strong sign that the item is not updating at the right time. You called getAdapter (). NotifyDataSetChanged () in DynamicListView, but that's only good for 2 items being moved. An item not being moved, the original item remains in the same wrong position, but needs to be updated to update to the correct position. Visually, I know it's not obvious!

I suspect the getView method in NavigationDrawerListViewAdapter needs updating. The getView method is responsible for displaying all items in Listiview! The code in getView has a rather strange coding technique and should be coded in the usual way as suggested by the developer google.android.com. The good part is, I think you don't need major code updates to fix your problem.

Code suggestion:



public View getView(final int position, View convertView, final ViewGroup parent) {
    ViewHolder holder = null;

    final NavigationDrawerFragment.ListItem i = myItems.get(position);

    if (convertView == null) {
        holder = new ViewHolder();
        convertView = mInflater.inflate(R.layout.navigation_drawer_listview_simple, null);

        holder.text = (TextView) convertView.findViewById(R.id.textView123);
        convertView.setTag(holder);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.text.setText(i.textdata);

    return convertView;
}

      

Notes:

  • The code holder.text.setText

    makes sure that even items that don't move are updated like others.
  • For clarification, if convertView

    is not = null, it means that the view has been refactored and rendered in the current view. I think this is your problem.
  • I noticed code using setTag method calls and I skipped them because I can't see what code is referencing those tags. Maybe you know better.
+3


source







All Articles