新手求助,spinner和listview的适配器
1个回答
2016-04-17
展开全部
adapter代码:
public class MyAdapter extends ArrayAdapter<Person> {
private int resourceId;
public MyAdapter(Context context, int resource, List<Person> objects) {
super(context, resource, objects);
resourceId = resource;
}
private class ViewHolder {
TextView name = null;
TextView number = null;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewHolder viewHolder = null;
if (view == null) {
viewHolder = new ViewHolder();
view = LayoutInflater.from(getContext()).inflate(resourceId, null);
viewHolder.name = (TextView) view.findViewById(R.id.sp_list_name);
viewHolder.number = (TextView) view.findViewById(R.id.sp_list_number);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
Person person = getItem(position);
viewHolder.name.setText(person.name);
viewHolder.number.setText(person.number);
return view;
}
}
public class MyAdapter extends ArrayAdapter<Person> {
private int resourceId;
public MyAdapter(Context context, int resource, List<Person> objects) {
super(context, resource, objects);
resourceId = resource;
}
private class ViewHolder {
TextView name = null;
TextView number = null;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewHolder viewHolder = null;
if (view == null) {
viewHolder = new ViewHolder();
view = LayoutInflater.from(getContext()).inflate(resourceId, null);
viewHolder.name = (TextView) view.findViewById(R.id.sp_list_name);
viewHolder.number = (TextView) view.findViewById(R.id.sp_list_number);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
Person person = getItem(position);
viewHolder.name.setText(person.name);
viewHolder.number.setText(person.number);
return view;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询