Javascript 嵌套滚动视图中的ListView onscroll侦听器提供了错误的最后可见项
我正在NestedScrollView中尝试此ListView,并向其中添加onScroll侦听器,但当我尝试获取ListView.getLastVisiblePosition()时,它为我提供了列表中的最大项,而不是最后一个可见项。如何获得与没有NestedScrollView的listview相同的结果 谢谢你的帮助,谢谢 我的onScrollListener代码Javascript 嵌套滚动视图中的ListView onscroll侦听器提供了错误的最后可见项,javascript,android,listview,android-nestedscrollview,Javascript,Android,Listview,Android Nestedscrollview,我正在NestedScrollView中尝试此ListView,并向其中添加onScroll侦听器,但当我尝试获取ListView.getLastVisiblePosition()时,它为我提供了列表中的最大项,而不是最后一个可见项。如何获得与没有NestedScrollView的listview相同的结果 谢谢你的帮助,谢谢 我的onScrollListener代码 listView.setOnScrollListener(new AbsListView.OnScrollListener()
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {}
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
Log.d("scroll", "scroll: " + listView.getLastVisiblePosition());
}
});
我的xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_merchant">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ListView">
</ListView>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
嗯,这是预期的行为。由于您的列表包含在一个滚动视图中,它已经完全展开。已经找到另一个解决方案了,无论如何thx@Selçukcihanaded代码对我有效:)您的“NestedScrollView”代码对我有效:)谢谢,这是预期的行为。由于您的列表包含在滚动视图中,因此已完全展开。已找到另一个解决方案,无论如何,thx@Selçukcihanaded代码适用于我:)您的“NestedScrollView”代码适用于我:)谢谢
nest.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY)
{
//get current height of screen and total height
Display display = getWindowManager().getDefaultDisplay();
final int stageHeight = display.getHeight();
int currentheight = stageHeight+scrollY;
int maxheight = listView.getHeight();
Log.d("myarc","aaa "+ currentheight +" bbb "+ maxheight);
if(currentheight>=maxheight && (update))
{
//turn off autoupdate
update=false;
Log.d("myarc","masuk bro ");
//add new item
RowItem item = new RowItem(R.drawable.wp, "GG", "GGWP");
rowItems.add(item);
//refresh listview
dataAdapter.notifyDataSetChanged();
setListViewHeightBasedOnItems(listView);
}
}
});