我使用 json 从 web 服务获取所有数据,然后在 gridview 中显示。我的主要任务是对 gridview 数据 AZ、ZA 和价格进行排序
//Here is the code which I used but its not show any kind of result.
switch (position)
{
case 0:
searchlist = new ArrayList<CakeC>();
Collections.sort(searchlist, new Comparator<CakeC>() {
@Override
public int compare(CakeC lhs, CakeC rhs) {
return -lhs.product_title.compareTo(rhs.product_title);
}
});
adapter.notifyDataSetChanged();
Log.e("Sort Data", searchlist.toString());
Toast.makeText(getActivity(), "you choose View" + itemValue, Toast.LENGTH_LONG).show();
break;
case 1:
Comparator<CakeC> cmp = new Comparator<CakeC>() {
public CakeC oi1;
public CakeC oi2;
@Override
public int compare(CakeC o1, CakeC o2) {
int oi1= Integer.parseInt(Global.cakename.product_price.toString());
this.oi1=o1;
int oi2= Integer.parseInt(Global.cakename.product_price.toString());
this.oi2=o2;
return oi1 - oi2;
}
};
searchlist = new ArrayList<CakeC>();
Collections.sort(searchlist, cmp);
adapter.notifyDataSetChanged();
Log.e("Sort Values",searchlist.toString());
break;
}