Adapter for a List displayed inside a Scroll View, non-Scrolling List View?

风格不统一 提交于 2019-12-12 02:47:42

问题


In the app I am currently building I have been synchronizing ListViews with unbound Lists of data via BaseAdapter. This has been working so far but now I need to have a list of data inside a ScrollView. The problem with putting a ListView inside a ScrollView is that both views scroll and it make the activity difficult to navigate. From what I've read online the consensus seems to be that ListViews should never be put inside of scroll views for this reason, and that a LinearLayout or TableLayout should be used instead.

My quesion is this: Can any one tell me either how to get rid of the Scrolling Feature on a ListView or how to synchronize a List of data with a LinearLayout or a TableLayout through an adapter?


回答1:


You could make your own custom ListView component and then override the dispatchTouchEvent() method:

@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
    int action = event.getAction();
    if (!scrollEnabled) {
        event.setAction(MotionEvent.ACTION_CANCEL);
        super.dispatchTouchEvent(event);
        return true; 
    }

    return super.dispatchTouchEvent(event);
}

In these kinds of situations though, what I've done in the past is have a separate vertical LinearLayout for my list and manually added TextViews via code to it, making it look similar to a listview.



来源:https://stackoverflow.com/questions/7772540/adapter-for-a-list-displayed-inside-a-scroll-view-non-scrolling-list-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!