tags:

views:

129

answers:

4

Hello, When I do a ListActivity my ListView works correctly : I can scroll by dragging with the TouchScreen or with the Mouse Wheel. However when I incorporate a ListView in a layout (with buttons, textview, linearLayouts, ect... ) I can't scroll it by dragging, I can just scroll with the mouse wheel.

How can I enable the "touch" scroll of a listView (outside a list activity) ?

Thanks

A: 

Embed it in a ScrollView.

EboMike
No, a ListView should not be put in a ScrollView. It is by definition already scrollable.
Mayra
I've tried and it doesn't work if I put it in ScrollView...
Trox
A: 
<LinearLayout
android:id="@+id/results_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/panel_background"
android:orientation="vertical"
android:layout_marginTop="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:visibility="invisible">         
        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/results"
        android:textSize="18sp"
        android:textStyle="bold"
        android:shadowColor="#7299e1"
        android:shadowRadius="2.0"
        android:shadowDx="3"
        android:shadowDy="2"
        android:gravity="center"/>
        <TextView
        android:id="@+id/results_panel_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/not_found"
        android:textSize="18sp"
        android:gravity="center"/>      
        <ListView
        android:id="@+id/results_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#0000"
        android:background="#0000"
        android:layout_weight="0.5"/>           
</LinearLayout>

The first linear layout Visibility is set programmaticaly to visible (so don't worry about that;)).

The first TextView is a title which appear above the ListView.

The second TextView Visibility is set to visible if I have no item otherwise to gone.

The ListView display the items and is set to visible if I have items otherwise to gone.

The items are Strings in a string Array displayed with an Array adapter.

Trox
+1  A: 

Try adding android:isScrollContainer="true" to your ListView definition. That ought to do it.

Another couple points of advice:

  • You can have the ListView automatically show the "Not found" TextView by using ListView.setEmptyView()
  • You should use dip or pt for your fonts, not sp. Try your app out on 3 different AVDs, one with a QVGA skin, one with HVGA, and one with WVGA, and I think you'll see what I mean. I would recommend pt except for the fact that the Droid has a glaring bug which causes font points to be incorrectly scaled. Try dips instead.
Neil Traft
Thank you for your advices :) , android:isScrollContainer="true" doesn't work :( .I really don't know why it's not working, as I told you my ListActivity scroll perfectly (touch event + trackball) but this ListView just scroll with the trackball. I can click/touch an item but can't scroll by dragging.
Trox
A: 

Eventually I've found out ! Sorry it's entirely my fault : my layout is really complex and I've shown you the part containing the listView but I had forgotten that my whole screen was embedded in a scrollview. And so there was a conflict between this listView and the ScrollView parent.

Excuse me again and thank you for your answers and advises !

Trox