/**
* 主页菜单适配器
*/
public class MainMenuAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private List<Authority> authorityList;
public MainMenuAdapter(Context context, List<Authority> authorityList) {
this.layoutInflater = LayoutInflater.from(context);
this.authorityList = authorityList;
}
@Override
public int getCount() {
return authorityList.size();
}
@Override
public Authority getItem(int position) {
return authorityList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder ;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.main_menu_item, parent, false);
holder.imageView = convertView.findViewById(R.id.btn);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Authority authority = authorityList.get(position);
holder.imageView.setImageResource(authority.getImage());
return convertView;
}
class ViewHolder {
ImageView imageView;
}
}
网友评论