1

I try to prevent a listview from scrolling. i've seen on other topic ( such as How to get a non scrollable ListView?) to use a Linear layout instead. However, it is not possibble in my application, my listview is filled programmably and so I need this component. Thanks for the response

Edit : it seems the easyest way to do it without changing my whole code is to add the others item from the scroolview in the listview as header,so I don't need a scroolview anymore.

however, then the listview adaper just seem to not be working. i've seen that I have to use a wrappedListadapter, but I cannot figure how to do it.

here is the code I use to set the adapter :

    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);
Community
  • 1
  • 1
wazaminator
  • 245
  • 3
  • 15
  • If you put few elements in the list, it won't be scrollable. Otherwise, I really suggest switching to LinearLayout. – MaciejGórski Apr 22 '13 at 10:44
  • the problem is, I do not know how many element will be in my listview, so I have to use a simpler adapter to fill it. – wazaminator Apr 22 '13 at 10:46
  • I tried using a addHeaderView() to enter the other part off the scrooling inside the listview, but it just crash on start... – wazaminator Apr 22 '13 at 13:23
  • If you don't know the elements count why would you want to stop it from scrolling? – MaciejGórski Apr 22 '13 at 13:27
  • what i'm trying to achieve is to get a relative layout and my listview in the same scroll, and if my listviex scroll,the upper scroll doesn't work. I tried to use a addheader(view) but then the aplication just crash – wazaminator Apr 22 '13 at 13:43
  • Consider adding such information to the question when you ask it. You never put a ListView inside ScrollView. Just don't. They are not meant to work with each other. – MaciejGórski Apr 22 '13 at 13:46
  • and,if I get rid of the scroolview, how do I get my other elements inside the listview,appart from addheader, who just semm to be not working? sorry for the strange question – wazaminator Apr 22 '13 at 13:48
  • I really suggest switching to LinearLayout. – MaciejGórski Apr 22 '13 at 13:50
  • but by using a linear_layout,how would I add my "list" inside,since I don't kwon how many element will come? – wazaminator Apr 22 '13 at 13:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28669/discussion-between-wazaminator-and-maciejgorski) – wazaminator Apr 22 '13 at 14:42

2 Answers2

2

I would use an View.OnTouchListener and simply use something like

if(event.getAction == MotionEvent.ACTION_MOVE) {
     // Ignore move events
     return true;
} else {
     return false;
}
Goddchen
  • 4,459
  • 4
  • 33
  • 54
  • where would you put that? in the Java code, on the listview,as new on touch listener? – wazaminator Apr 22 '13 at 10:48
  • yes, listview.setOnTouchListener(new View.OnTouchListener(...)); – Goddchen Apr 22 '13 at 10:49
  • the program just crash... i've added this, where liste is my listeview liste.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } }); – wazaminator Apr 22 '13 at 10:55
1

The best way I found so far is to create a custom listivew.

Basically, you ignore move event(which happens between touch down and up). But the issue is that when touch down an item, then move your finger out of the item, it still fires touch up event.

See this link

Sébastien
  • 11,860
  • 11
  • 58
  • 78
dafeilei
  • 11
  • 1