2

Hi I'm using the TouchListView control from here: https://github.com/commonsguy/cwac-touchlist and I've added some buttons to add to the list in the footer:

    mFooter = getLayoutInflater().inflate(R.layout.edit_homepage_footer_layout, null);
    mListView = (TouchListView) findViewById(R.id.sectionList);
    mListView.addFooterView(mFooter);

It all seems to be working fine until I drag an item in the list, at which point the footer collapses (to the height of one list item I think) obscuring the buttons I have added.

Can anyone suggest a fix/workaround for this?

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Rupert Bates
  • 3,041
  • 27
  • 20
  • Hmmm... haven't tried `TouchListView` with headers or footers. I'm not terribly shocked that there are issues, though. If you can edit your question with a link to a sample project that demonstrates the issue, I can see if there is a simple fix. – CommonsWare Jul 15 '11 at 16:00
  • I can't comment on this issue, but just wanted to say: Mark Murphy - I'm in awe of you. You are always on hand to help people out - I've never known one person to contribute so much to a development environment as you have. I, sir, salute you. Bravo. – Martyn Jul 15 '11 at 16:05

1 Answers1

2

I actually worked this out shortly after asking it (always the way...)

The issue is in the doExpansion() and unExpandViews() methods which were modifying every item in the list including the footer. To fix it I created a method to check whether we are dealing with a draggable item or the footer:

private boolean isDraggableItem(View view) {
    View dragger = view.findViewById(grabberId);
    return dragger != null;
}

And then modified the methods mentioned as follows:

private void unExpandViews(boolean deletion) {
    for (int i = 0; ; i++) {
        View v = getChildAt(i);
        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;
            }
        }
        if (isDraggableItem(v)) { //check this view isn't the footer
            ViewGroup.LayoutParams params = v.getLayoutParams();
            params.height = mItemHeightNormal;
            v.setLayoutParams(params);
            v.setVisibility(View.VISIBLE);
        }
    }
}

private void doExpansion() {
    Log.d(logTag, "Doing expansion");
    int childnum = mDragPos - getFirstVisiblePosition();
    if (mDragPos > mFirstDragPos) {
        childnum++;
    }

    View first = getChildAt(mFirstDragPos - getFirstVisiblePosition());

    for (int i = 0; ; i++) {
        View vv = getChildAt(i);
        if (vv == null) {
            break;
        }
        int height = mItemHeightNormal;
        int visibility = View.VISIBLE;
        if (vv.equals(first)) {
            // processing the item that is being dragged
            if (mDragPos == mFirstDragPos) {
                // hovering over the original location
                visibility = View.INVISIBLE;
            } else {
                // not hovering over it
                height = 1;
            }
        } else if (i == childnum) {
            if (mDragPos < getCount() - 1) {
                height = mItemHeightExpanded;
            }
        }
        if (isDraggableItem(vv)) { //check this view isn't the footer
            ViewGroup.LayoutParams params = vv.getLayoutParams();
            params.height = height;
            vv.setLayoutParams(params);
            vv.setVisibility(visibility);
        }
    }
}

Would be worth updating the github project to include this I think.

Rupert Bates
  • 3,041
  • 27
  • 20
  • Yeah, I'll need to do something. I'll see if I can come up with a more positive test than "doesn't have the dragger icon", though if needed "can't have dragger in header/footer" isn't an unreasonable restriction. I'll try to get something put in there soonish. Many thanks! – CommonsWare Jul 15 '11 at 16:52
  • I just released v0.3.0 of the project that incorporates your fixes. I also added some more smarts to prevent crashes if the user tries to drag the footer itself. Note that this fix does *not* work for headers -- something gets messed up in the row calculations, so drags and drops get mis-positioned. I will look to fix that portion of matters sometime in the future. Thanks for your help! – CommonsWare Jul 20 '11 at 22:37
  • @CommonsWare, i don't need drag-n-drop support for first three items of list, is this work for that? – Bipin Vayalu Oct 30 '13 at 20:57
  • @BipinVayalu: I discontinued my project several months ago, sorry. – CommonsWare Oct 30 '13 at 21:57