Fil*_*eOS 9 java sorting android adapter
我正在尝试按距离重新排序我的项目列表(使用android getListView,而不是自定义),我遇到了问题.
我使用适配器内的Maps Utils (SomeAdapter)获得以米为单位的球形距离(双倍).
double distance = SphericalUtil.computeDistanceBetween(fromCoord, toCoord);
但是在我填充适配器(AsyncTask)后,我需要在onPostExecute上缩短距离,我不知道.
@Override
protected void onPostExecute(Boolean result) {
try {
SQLiteHelper dbHelper = new SQLiteHelper(getActivity());
pds = new SomeDataSource(dbHelper.db);
ArrayList<Raids> some = pds.getAllRaids();
SomeAdapter listViewAdapter = new SomeAdapter(getActivity(), some);
getListView().setAdapter(listViewAdapter);
SharedPreferences somename = context.getSharedPreferences("SomeName", Context.MODE_PRIVATE);
Boolean UserOrder = somename.getBoolean("UserOrder", false);
if (UserOrder){
}
} catch (SQLiteException | NullPointerException s) {
Log.d("SomeName", "SomeFrag:", s);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
只需Comparable在您的Raids课程中实现界面-
class Raids implements Comparable<Raids> {
private double distance;
...
@Override
public int compareTo(Raids instance2) {
if (this.distance < instance2.distance)
return -1;
else if (this.distance > instance2.distance)
return 1;
else
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
然后打电话Collections.sort给它 -
ArrayList<Raids> some = pds.getAllRaids();
Collections.sort(some);
Run Code Online (Sandbox Code Playgroud)
并更新适配器 -
listViewAdapter.notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
249 次 |
| 最近记录: |