有人可以請幫我我有一個GridView的滾動問題我做的是我從API顯示GridView中的前10個產品..現在我需要的是 - 當用戶滾動並且獲取列表的最後位置,然後API再次以頁面值2命中..並且滾動顯示來自用戶所在的當前位置。現在顯示數據並且適配器改變其值。但是當滾動顯示在頂部時新的API點擊...任何人都可以告訴我該怎麼辦?非常感謝,請幫助..滾動位置不保存在Grdiview
我做什麼 -
grid.setOnScrollListener(new AbsListView.OnScrollListener() {
int last_item;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int lastitem = firstVisibleItem + visibleItemCount;
if(lastitem == totalItemCount){
HitApi();//This is the method where API hits with the new page value
}
}
});
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/products_GridView"
android:numColumns="auto_fit"
android:listSelector="@android:color/transparent"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
>
</GridView>
</LinearLayout>
我真的不明白你的目標!當用戶導航到其他活動並返回到GridView活動時,是否需要保存滾動位置?頁面值2是什麼意思?你可以向我們展示一個更好地描述這種情況的演示或屏幕截圖 –
不,我不打算接下來的活動。只是我的適配器數據隨着新值而改變,並且每當我滾動和數據改變時滾動在最佳。它會從新的數據加載或添加到列表中開始 –
我會假設你使用的是一個scrollView的權利?它是在一個linearLayout?請與我們分享您的xml –