【发布时间】:2016-11-18 12:16:45
【问题描述】:
我有一个包含 3 个不同值的列表视图。
值:
热门问题 (getField_top_problem)、
用户ID (getUid)
难度(getField_difficulty )
我想像这样对列表进行排序。
第一部分:
检查哪个用户已登录。获取该用户的所有热门问题。
登录用户的Top问题,需要先按照最难排序。
第二部分/列表的其余部分。
需要先按照最难的排序。是否存在来自其他未登录用户的 Top 问题无关紧要。(如果不确定,请检查图像 - 红色框)
到目前为止我的进步。
我能够对其进行排序,首先是所有用户的首要问题,而不仅仅是登录用户。需要根据登录用户的Top问题进行排序。登录用户的 id 保存为字符串。
//Example logged in user id (uid)
String uid = "2";
任何帮助将不胜感激。
protected void onPostExecute(final List<OcdModel> result) {
super.onPostExecute(result);
dialog.dismiss();
//uid - user id that is logged in.
//Sort - Top problem of user logged in first.
//sort the rest according to difficulty
//check which user is logged in.
//Boolean user1 = a1.getUid().equals(uid);
Collections.sort(result, new Comparator<OcdModel>() {
@Override
public int compare(OcdModel a1, OcdModel a2) {
//Top problem first. Arrange row with most difficult first in top problems list.
Integer tp1 = Integer.parseInt(a1.getField_top_problem().toString());
Integer tp2 = Integer.parseInt(a2.getField_top_problem().toString());
int tpComp = tp1.compareTo(tp2);
//return b1.compareTo(b2);
if (tpComp != 0) {
return tpComp;
} else {
int b1 = Integer.parseInt(a1.getField_difficulty().toString());
int b2 = Integer.parseInt(a2.getField_difficulty().toString());
return (int) (b1-b2);
}
}
});
Collections.reverse(result);
//TODO Need to set data
OcdListAdapter adapter = new OcdListAdapter(getApplicationContext(), R.layout.row_ocd_list, result);
lvToolbox.setAdapter(adapter);
}
提前致谢
【问题讨论】:
-
你必须从 api 开发者那里得到帮助。您需要为每个请求传递不同的参数键和值,例如 sort : (first-part some value identifier) 、 sort : (second-part some value identifier) 等