我想在我的Staggered gridview中實現加載更多的功能。我已經嘗試了一些代碼行,例如使用addOnScrollListener
,但當我到達列表的底部時沒有打電話。
請找到我的代碼,我試圖實現加載更多的功能,但沒有得到預期的結果。
交錯Gridview(Recycleview)加載更多的功能在NestedScrollView內
MY_STRAGGED_RECYCLIVIEW.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView,
int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
totalItemCount = staggeredGridLayoutManager.getItemCount();
lastVisibleItem = staggeredGridLayoutManager
.findLastCompletelyVisibleItemPositions(null)[0];
if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
System.out.println("I amm here dd ");
loading = true;
}
}
});
在我上面的代碼中,的System.out沒有得到打印...
我曾嘗試另一個偵聽器stragged gridview的是setOnScrollChangeListener
,但它也沒有工作
MY_STRAGGED_RECYCLIVIEW.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
System.out.println("I amm here fffffffffff ");
}
});
同樣的問題與此監聽器出現的時候,沒有得到打印我的System.out
更多的東西,我試圖在我的adapter
類的onBindViewHolder
方法是
if(getCount()==position)
{
////for getting the last item of the recycleview
}
上面的代碼中也沒有working..Please幫我短路從這個問題..謝謝:)
@Abbas請檢查下面
public class StraggredView extends RecyclerView.Adapter<StraggredView.ViewHolder> {
private List<Content> mDataSet;
private Context ctx;
public StraggredView(Context context, List<Content> arrList) {
ctx = context;
mDataSet = arrList;
}
@Override
public StraggredView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_grid, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
if(getItemCount()==position)
{
//// I AM NOT GETTING IT AT THE BOTTOM... IT INVOKED AS THE ADAPTER IS CALLED FIRST TIME...LOOK AT IT
}
if (mDataSet.get(position).getContentImage() == null || mDataSet.get(position).getContentImage().isEmpty()) {
Glide.with(ctx).load(R.drawable.no_content)
// .override(screenWidth/2, Utils.dpToPx(height))
.into(holder.imgContent);
} else {
Glide.with(ctx).load(mDataSet.get(position).getContentImage())
// .override(screenWidth/2, Utils.dpToPx(height))
// .centerCrop()
//.transform(new CircleTransform())
.into(holder.imgContent);
}
holder.imgContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDataSet.get(position).getContentImage() != null
|| !mDataSet.get(position).getContentImage().isEmpty()) {
FragmentActivity activity = (FragmentActivity) (ctx);
FragmentManager fm = activity.getSupportFragmentManager();
FullScreenFragment dialog = FullScreenFragment.newInstance(
mDataSet.get(position).getContentImage());
dialog.show(fm, "dialog");
}
}
});
}
@Override
public int getItemCount() {
return this.mDataSet.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView imgContent;
public ViewHolder(View itemView) {
super(itemView);
imgContent = (ImageView) itemView.findViewById(R.id.imgContent);
}
}
}
你可以使用這個鏈接:http://stackoverflow.com/questions/8664935/android-loading-data-like-facebook-and-twitter –
@AmitRanjan。 。我已經嘗試過上面的鏈接,它也不工作的情況下,gridview –
你能看到這段代碼:http://stackoverflow.com/questions/16851934/android-onscrolllistener-for-staggered-grid-view –