android使listview不可滚动

时间:2013-04-22 10:43:48

标签: android listview scroll

我尝试阻止列表视图滚动。 我已经在其他主题(例如How to get a non scrollable ListView?)上看到使用线性布局。 但是,它在我的应用程序中是不可能的,我的listview是可编程填充的,所以我需要这个组件。 感谢您的回复

编辑:在不更改我的整个代码的情况下,最简单的方法是将listview中scroolview中的其他项添加为标题,这样我就不再需要scroolview了。

然而,listview adaper似乎不起作用。我已经看到我必须使用wrappedListadapter,但我无法想象如何去做。

这是我用来设置适配器的代码:

    SimpleAdapter mSchedule = new SimpleAdapter(this.getBaseContext(), listItem, R.layout.consultafficheitem,
           new String[] {"description", "ingredient"}, new int[] {R.id.consultlistdescription, R.id.consultlistingredients});


    scroll = (RelativeLayout) findViewById(R.id.consultscrollrelativelayout);
    liste.addHeaderView(scroll);

    liste.setAdapter(mSchedule);

2 个答案:

答案 0 :(得分:2)

我会使用View.OnTouchListener并使用类似

的内容
if(event.getAction == MotionEvent.ACTION_MOVE) {
     // Ignore move events
     return true;
} else {
     return false;
}

答案 1 :(得分:1)

到目前为止,我发现的最好的方法是创建一个自定义的listivew。

基本上,您忽略移动事件(在触地和向上之间发生)。但问题是,当触摸一个项目,然后将手指移出项目时,它仍然会触发事件。

请参阅this link

相关问题