在我的Listview中,我希望app_id匹配android app中另一个名为def的变量的行成为第一个索引。换句话说,我不是只填充列表视图,因为它已经排序,我想基本上取一行并将其移到顶部。在下面的ApplicationAdapter中有一种简单的方法吗?
public class ApplicationAdapter extends ArrayAdapter<Application>{
private List<Application> items;
public ApplicationAdapter(Context context, List<Application> items) {
super(context, R.layout.app_custom_list, items);
this.items = items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null) {
LayoutInflater li = LayoutInflater.from(getContext());
v = li.inflate(R.layout.app_custom_list, null);
}
Application app = items.get(position);
if(app != null) {
ImageView icon = (ImageView)v.findViewById(R.id.iconImg);
TextView titleText = (TextView)v.findViewById(R.id.titleTxt);
TextView descText = (TextView)v.findViewById(R.id.descTxt);
TextView creatorText = (TextView)v.findViewById(R.id.creatorTxt);
TextView createdText = (TextView)v.findViewById(R.id.createdTxt);
TextView rankText = (TextView)v.findViewById(R.id.rankTxt);
if(icon != null) {
Resources res = getContext().getResources();
String sIcon = "com.sj.jsondemo:drawable/" + app.getIcon();
icon.setImageDrawable(res.getDrawable(res.getIdentifier(sIcon, null, null)));
}
if(titleText != null) titleText.setText(app.getTitle());
if(descText != null) descText.setText(app.getDesc());
if(creatorText != null) creatorText.setText(app.getCreator());
if(createdText != null) createdText.setText(app.getCreated());
if(rankText != null) rankText.setText(app.getRank());
}
答案 0 :(得分:1)