0

I have a ListView inside a ScrollView, and I can scroll the contents of he list via my optical mouse button on my HTC Wildfire - it's like a physical cursor up/down thing. So far so good. The bad thing is that I cannot scroll the list by the normal touch/swipe that normally works on this kind of lists.

What could be wrong?

My layout is like this:

<?xml version="1.0" encoding="utf-8"?>

  <ScrollView android:id="@+id/scroll" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    xmlns:android="http://schemas.android.com/apk/res/android">

        <ListView android:id="@+id/MessageList"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

  </ScrollView>

And some Java code to initialize the list:

public class MorseIt extends Activity {

    private ListView lv1;
    private String lv_arr[]={"Red","Green","Blue","Purple","White","Black","Pink","Cyan","Magenta"};


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        lv1=(ListView)findViewById(R.id.MessageList);
     lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));

    }
}
  • Why put the ListView inside a ScrollView when the ListView itself is scrollable...? – TofferJ May 17 '11 at 10:29
  • welcome to stackoverflow by the way. If you find an answer answered your question, please accept it and/or upvote it. Also please double check spelling and search for duplicates before posting a question as described here: http://stackoverflow.com/questions/how-to-ask – vidstige May 17 '11 at 15:08

1 Answers1

2

This is a very common problem. The ListView itself will scroll for you, using your current layout is against the purpose of the ListView. Either drop the ListView and use a regular LinearLayout, or drop the ScrollView and use the ListView properly. Also see this question.

Community
  • 1
  • 1
vidstige
  • 12,492
  • 9
  • 66
  • 110