public class CustomAdaptor extends BaseAdapter {
Context context;
List<Rowitem> rowItems;
CustomAdaptor(Context context, List<Rowitem> rowitems) {
this.context = context;
this.rowItems = rowItems;
}
public int getCount() {
return rowItems.size();
}
public Object getItem(int position) {
return rowItems.get(position);
}
public long getItemId(int position) {
return rowItems.indexOf(getItem(position));
}
private class ViewHolder {
ImageView profile_pic;
TextView Employees;
TextView status;
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.Employees = (TextView) convertView.findViewById(R.id.emp);
holder.profile_pic = (ImageView) convertView.findViewById(R.id.profile_pic);
holder.status = (TextView) convertView.findViewById(R.id.status);
Rowitem row_pos = rowItems.get(position);
holder.profile_pic.setImageResource(row_pos.getProfile_pic_id());
holder.Employees.setText(row_pos.getEmployees());
holder.status.setText(row_pos.getStatus());
}
}
}
}
朋友您好,这是我的自定义适配器,我收到此错误:-CustomAdaptor不是抽象的,并且不会覆盖适配器中的抽象方法getView(int,View,ViewGroup).......你能帮助吗?我在这? 谢谢!
答案 0 :(得分:0)
将getView()
方法放在Holder Class
public class CustomAdaptor extends BaseAdapter {
Context context;
List<Rowitem> rowItems;
CustomAdaptor(Context context, List<Rowitem> rowitems) {
this.context = context;
this.rowItems = rowItems;
}
public int getCount() {
return rowItems.size();
}
public Object getItem(int position) {
return rowItems.get(position);
}
public long getItemId(int position) {
return rowItems.indexOf(getItem(position));
}
private class ViewHolder {
ImageView profile_pic;
TextView Employees;
TextView status;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.Employees = (TextView) convertView.findViewById(R.id.emp);
holder.profile_pic = (ImageView) convertView.findViewById(R.id.profile_pic);
holder.status = (TextView) convertView.findViewById(R.id.status);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Rowitem row_pos = rowItems.get(position);
holder.profile_pic.setImageResource(row_pos.getProfile_pic_id());
holder.Employees.setText(row_pos.getEmployees());
holder.status.setText(row_pos.getStatus());
}
}
答案 1 :(得分:0)
将getView()方法放在holderclass的一边,并编写一个return convertview语句。
public class CustomAdaptor extends BaseAdapter {
Context context;
List<Rowitem> rowItems;
CustomAdaptor(Context context, List<Rowitem> rowitems) {
this.context = context;
this.rowItems = rowItems;
}
public int getCount() {
return rowItems.size();
}
public Object getItem(int position) {
return rowItems.get(position);
}
public long getItemId(int position) {
return rowItems.indexOf(getItem(position));
}
private class ViewHolder {
ImageView profile_pic;
TextView Employees;
TextView status;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.Employees = (TextView) convertView.findViewById(R.id.emp);
holder.profile_pic = (ImageView) convertView.findViewById(R.id.profile_pic);
holder.status = (TextView) convertView.findViewById(R.id.status);
Rowitem row_pos = rowItems.get(position);
holder.profile_pic.setImageResource(row_pos.getProfile_pic_id());
holder.Employees.setText(row_pos.getEmployees());
holder.status.setText(row_pos.getStatus());
}
return convertView;
}
}