0

I did get the drag and drop working and the TouchListView class works great. However in my case I have rows of various height due to my adapter which contains an EditText that can have multiple lines. Therefore after I drop, all my rows convert to the tlv:normal_height which in my case is 74dip. This causes many rows to cut off all my text in the EditTexts. I tried re initializing my adapter (mylistview.setAdapter= myadapter), setting the ListView to GONE then VISIBLE and invalidateViews() but nothing seems to reset the ListView back to before I dragged, short of leaving the activity and coming back. What can be done here? -Thx

tlv:normal_height="74dip"
tlv:expanded_height="128dip"
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Mike6679
  • 5,547
  • 19
  • 63
  • 108

2 Answers2

0

There's little question that the original AOSP code was designed for uniform row heights, and the whole expanded_height construct was there to provide space for the user to visualize where the drop would occur.

One starting point would probably be to create a TouchListAdapter mixin interface (akin to SpinnerAdapter) where the normal_height and expanded_height would be retrieved dynamically from the adapter based on position as opposed to being fixed values declared in the layout. Whether that alone would be sufficient or more work would need to be done, I can't say.

If you come up with a solution, patches are welcome. Otherwise, I'll probably take a look at this sometime, but not very soon.

My apologies for not having a near-term silver bullet.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I see, thanks. I will see if I can edit the TouchListView class a bit and see if I can set the row heights dynamically based on the ListView item's height. I assume I can access the ListView' adapter from the TouchListView class - so can you point me to the right location in the code? – Mike6679 Jan 11 '12 at 17:19
  • @Mike: Use `getAdapter()` to get the adapter. – CommonsWare Jan 11 '12 at 17:21
0

I edited the unExpandViews() method - called getAdapter() and for every item in my adapter set the height to 0 and then all the rows were set back to original. I also bypassed the delete part of the method since it did not apply to me.

private void unExpandViews(boolean deletion) {

            int height_saved = 0;

            CheckBoxifiedTextListAdapter cbla = (CheckBoxifiedTextListAdapter)getAdapter();

            for (int i = 0;i < cbla.getCount(); i++) 
            {
                    //View v = getChildAt(i);

                    View v = cbla.getView(i, null, null);

                    //if (v == null) 
                    //{      
                           /*
                            if (deletion) 
                            {
                                    // HACK force update of mItemCount
                                    int position = getFirstVisiblePosition();
                                    int y = getChildAt(0).getTop();
                                    setAdapter(getAdapter());
                                    setSelectionFromTop(position, y);
                                    // end hack
                            }
                            layoutChildren(); // force children to be recreated where needed
                            v = getChildAt(i);

                            if (v == null) 
                            {
                                    break;
                            }
                            height_saved = v.getHeight();
                            */
                    //}
                    //else

                    //height_saved = v.getHeight();

                    if (isDraggableRow(v)) 
                    {
                        ViewGroup.LayoutParams params = v.getLayoutParams();
                        params.height = 0;
                        v.setLayoutParams(params);
                        v.setVisibility(View.VISIBLE);
                    }
            }
    }
Mike6679
  • 5,547
  • 19
  • 63
  • 108