我想在recyclerview中显示一些JSON对象,并且希望它们在日期之后排序,我该如何实现?下面是下载从JSON URL的数据的方法:Android Studio Studio回收列表中的JSON对象
public void downloadFromSkistar()
{
try
{
URL url = new URL("XXXXX");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
// Starts the query
conn.connect();
int response = conn.getResponseCode();
Log.i("AndroidExample", "Response: " + response);
if (response == 200)
{
String json = getJson(conn.getInputStream());
JSONObject jsonObject = new JSONObject(json);
JSONArray jsonArray = jsonObject.getJSONArray("rideStatistics");
int reponame = 0;
for (int i = 0; i < jsonArray.length(); i++)
{
JSONObject skiRun = jsonArray.getJSONObject(i);
reponame += skiRun.getInt("height");
}
final int height = reponame;
final int count = jsonArray.length();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
dropHeight.set("" + height);
rideCount.set("" + count);
}
});
}
}
catch (Exception e)
{
Log.i("AndroidExample", "Error");
}
finally
{
}
}
我不知道我是否能提供足够的信息,因为我很新的这一点,基本上是我想要的是显示JSON对象内我的回收查看列表与最新日期第一等对象
+0
您需要创建循环视图自定义适配器接受JSON对象和显示 –
+0
可能重复:http://stackoverflow.com/questions/32562107/how -to-排序的数据功能于recyclerview –