我正致力于一个在移动和网络平台上工作的项目。 我正在使用autofac作为依赖解析器,它适用于web但webapi控制器中的构造函数参数不能初始化
我试过
http://docs.autofac.org/en/latest/register/parameters.html 请帮忙
答案 0 :(得分:0)
Plz试试这个......
public class MapAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
private List<MapSetData> venues;
public Context context;
public MapAdapter(List<MapSetData> venues, Context context) {
this.venues = venues;
this.context = context;
}
@Override
public VenuesViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_item, viewGroup, false);
VenuesViewHolder pvh = new VenuesViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
VenuesViewHolder holder = (VenuesViewHolder) viewHolder; holder.venues_picture.setImageResource(venues.get(position).venue_picture);
holder.card_title_txt.setText(venues.get(position).card_title_txt);
holder.location_qs.setText(venues.get(position).location_qs);
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position) == 0) {
return TYPE_HEADER;
} else if (isPositionHeader(position) == 1) {
return TYPE_ITEM;
} else {
return 0;
}
}
private int isPositionHeader(int position) {
return position;
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@Override
public int getItemCount() {
return venues.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View v) {
super(v);
}
}
public class VenuesViewHolder extends ViewHolder implements View.OnClickListener {
ImageView venues_picture;
TextView card_title_txt;
TextView location_qs;
CardView cv;
public Context context;
public VenuesViewHolder(View v) {
super(v);
v.setOnClickListener(this);
context = v.getContext();
cv = (CardView) itemView.findViewById(R.id.cv);
venues_picture = (ImageView) itemView.findViewById(R.id.match_picture);
card_title_txt = (TextView) itemView.findViewById(R.id.card_title_txt);
location_qs = (TextView) itemView.findViewById(R.id.location_qs);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MapDetails.class);
context.startActivity(intent);
}
}
}