Storing seekbar values after drag drop process end in ListView

232 views Asked by At

I have listView with drag drop functionality. I'm using ListView with custom layout- I have SeekBar and TextView in custom ListView layout. When I drag and drop each ListView items after changing SeekBar value, TextView is moving and SeekBar value is not moving.

It may be caused by Adapter. So I've share my adapter codes.

https://gist.github.com/salihyalcin/38e320726e3ab8346c50

Thanks in advance

EDIT --- My ListItem Class

 class ListItem {
    String textdata;

    public ListItem(String textdata) {
        this.textdata = textdata;
    }


    public boolean equals(Object o) {
        ListItem ndListItemObject = (ListItem) o;
        return this.textdata.equalsIgnoreCase(ndListItemObject.textdata);
    }


}

** My ListView looks like image below

enter image description here

** Change the SeekBar value of Layer1

enter image description here

** Drag-Drop Layer1 and Layer2

enter image description here

** Layer1 and Layer2 moved but SeekBar values stay same place, they didn't moved.

First Situation

1

There are 1 answers

5
The Original Android On

I think I have an idea. First, your post is missing code snippet of the definition of NavigationDrawerFragment.ListItem class, could be helpful. I do remember that you call method swapElements in DynamicListView but other readers probably don't need to know it.

My suggestion is to save the progress value into the ListItem class, sample code below. We will depend on swapElements() to swap the 2 ListItem objects properly, along with the progress and text (layers in your case).

EDIT, code suggestion for ListItem class:

class ListItem {
    String textdata;
    int seekBarValue;

    public ListItem(String textdata) {
        this.textdata = textdata;
    }

    public ListItem(String textdata, int seekBarValue) {
        this.textdata = textdata;
        this.seekBarValue = seekBarValue;
    }
...

Notes for ListItem code:

  • Added seekBarValue as a public data member, and another ListItem constructor for the caller's convenience.
  • This is what I meant by add another data member to this class.

Code snippet suggestion for the Adapter:

holder.mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
   @Override
   public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      final NavigationDrawerFragment.ListItem item = myItems.get(position);

      View view = (View) seekBar.getParent();
      if (view != null) {
         holder.text.setText(progress + "%");
         item.seekBarValue = progress;

Notes:

  1. Added code line ...item = myItems.get(position); to get the correct item in the ArrayList.
  2. Set the progress to item.seekBarValue

You may remove these codes below unless you plan on using it, of course:

  • holder.mSeekBar.getTag();
  • holder.text.getTag();
  • mar.get(1,progress);