views:

1741

answers:

1

I have an ListView inside a HorizontalScrollView and it works perfectly fine, except for the initial load. I'm loading the data for the list view from a web service so I created a thread to do that. Once I have the data, I simply call _myListAdapter.notifyDataSetChanged(); and the data becomes visible in the ListView. But if the ListView is far off the screen, the containing HorizontalScrollView will automatically scroll to make this ListView visible. How can I call notifyDataSetChanged without making the ListView scroll into the current view?

Here's an idea of how I have my layout XML file:

<HorizontalScrollView 
 android:id="@+id/my_scrollview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 android:scrollbars="none">

     <LinearLayout android:id="@+id/my_layout"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:orientation="horizontal">

             <ListView android:id="@+id/my_list"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_weight="1" />

        </LinearLayout>

</HorizontalScrollView>
+1  A: 

I would try making your ListView invisible until after you've called notifyDataSetChanged().

<ListView android:id="@+id/my_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:visibility="gone"/>

Then in the code:

_myListAdapter.notifyDataSetChanged();
ListView listView = (ListView) findViewById(R.id.my_list);
listView.setVisibility(View.VISIBLE);

Not sure if this will work... worth a shot, though.

Daniel Lew
Yeah. I did this, but I didn't set to to "gone" initially, just "invisible". It does solve the problem, but I don't know. Seems like a workaround. Maybe I'll file a bug with the Android team - I can't find anything in the documentation which says I'm doing this wrong.Thanks for your answer.
marcc