我正在开发与媒体相关的应用程序,因为我需要逐个调用多个Web服务,并使用Cardview和Recycleview列出此元素。任何人都可以为我推荐我。如何使用JSON逐一解析多个Web服务和列表视图
在此先感谢。 Arasu
我正在开发与媒体相关的应用程序,因为我需要逐个调用多个Web服务,并使用Cardview和Recycleview列出此元素。任何人都可以为我推荐我。如何使用JSON逐一解析多个Web服务和列表视图
在此先感谢。 Arasu
您可以添加,因为它们是从这些网络服务收到您的适配器,并调用notifyDataSetChanged()
适配器上,使新项目在Recyclerview
显示新项目。喜欢的东西 -
if(mAdapter == null) {
// First item received, adapter not initialized yet.
mAdapter = new CustomAdapter(items);
mRecyclerView.setAdapter(mAdapter);
} else {
// Adapter already exists. Add received items to the adapter.
mAdapter.add(items);
mAdapter.notifyDataSetChanged();
}
如果我没有得到它,你必须调用几个WS和获取数据。那么你可以使用例如Volley或OkHttp来处理异步请求。
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
// notify error
}
@Override
public void onResponse(Response response) throws IOException {
// parse the data
}
}
});
当您准备好数据后,您将更新recyclerview后面的模型并显示新信息。 如果你有RecyclerView你可以创建这样的布局问题:
<RelativeLayout >
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
并且每行持有卡(行布局):
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">
.....
</android.support.v7.widget.CardView>
你可以给看看我的帖子里介绍how to use RecyclerView and CardView。 希望它可以帮助你!
是什么问题? –
我不知道如何在单个活动中使用多个Web服务,否则我需要使用String [] url = {...,.....,.....,....};就像它一样。 –