简体   繁体   English

使用 url 单击“更多”按钮加载更多回收站视图项目

[英]Load more recyclerview Items on click of “more” button with url

I am using retrofit to showing recyclerview items.我正在使用 retrofit 来显示 recyclerview 项目。 At first only two of them is visible but on clicking of "show more" button, I am trying to load rest of the items with api.起初只有两个可见,但单击“显示更多”按钮时,我正在尝试使用 api 加载项目的 rest。

my approach is to add more items with a url but not able to figure out if i am going in a correct way or not.我的方法是使用 url 添加更多项目,但无法确定我是否以正确的方式进行。

I am able to show starting 2 items and from back end, I am getting a url in "nextComments" tag.我能够显示开始的 2 个项目,从后端,我在“nextComments”标签中得到一个 url。 Passing this url as a parameter in api calling method.在 api 调用方法中将此 url 作为参数传递。 Trying to figure out the next approach试图找出下一个方法

Api.getReplies(nextUrl.toString())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(
            { result ->
                if (!result.results.isNullOrEmpty()) {
                    nextUrl = result.next.toString()


                    //-------what should be here-----//?
                    replyAdapter.notifyDataSetChanged()
                }
            },
            { error ->
                println(error)
            })

The items are expected to add in recyclerview, when i click on show more当我点击显示更多时,这些项目预计将添加到 recyclerview

It really depends on how your adapter code looks like, but here is a generic example:这实际上取决于您的适配器代码的外观,但这是一个通用示例:

//get the new items from backend
var more_objects = await MyWebService.GetMoreObjects (indexKey);
// add the items to the adapter
_adapter.appendObjects(more_objects);
_adapter.NotifyDataSetChanged ();

appendObjects in the adapter:适配器中的 appendObjects:

    public void appendObjects (List<MyObj> obj)
    {
        foreach (var o in obj) {
            data.Add (o);
        }
    }

appendObject in kotlin kotlin 中的附加对象

fun appendObjects(obj: List<MyObj>) {
    obj.forEach { 
        data.Add (it); 
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM