展开全部
代码片段如下636f70793231313335323631343130323136353331333339656534private void sortInfo() {
Comparator itemComparator = new Comparator() {
public int compare(InfoTmp info1, InfoTmp info2){
return info1.getAge().compareTo(info2.getAge());
}
};
Collections.sort(mProfileList, itemComparator);
}
[java] view plain copy
public class UserListAdapter extends BaseAdapter {
private Context mContext;
private List mUserList;
public UserListAdapter(Context context, List users) {
mContext = context;
mUserList = users;
}
public int getCount() {
return mUserList.size();
}
public Object getItem(int position) {
if (position >= mUserList.size()) {
return null;
}
return mUserList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.user_item, null);
TextView text = (TextView) convertView.findViewById(R.id.text);
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
ImageButton btnEdit = (ImageButton) convertView.findViewById(R.id.edit);
ImageButton btnDel = (ImageButton) convertView.findViewById(R.id.delete);
//... ...
return convertView;
}
}
[java] view plain copy
private void refreshAdapter() {
// ... ...
sortInfo();
mListVew.setAdapter(new UserListAdapter(mContext, mProfileList));
}