0

我有一个ListView内部 a HorizontalScrollView,它工作得非常好,除了初始负载。我正在从 Web 服务加载列表视图的数据,因此我创建了一个线程来执行此操作。一旦我有了数据,我只需调用_myListAdapter.notifyDataSetChanged();,数据就会在ListView. 但如果ListView远离屏幕,包含HorizontalScrollView将自动滚动以使其ListView可见。如何notifyDataSetChanged在不ListView滚动到当前视图的情况下调用?

这是我如何拥有布局 XML 文件的想法:

<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>
4

1 回答 1

0

我会尝试让您的 ListView 不可见,直到您调用notifyDataSetChanged().

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

然后在代码中:

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

不确定这是否会奏效……不过,值得一试。

于 2009-12-10T05:41:02.143 回答