public class GridElementAdapter extends RecyclerView.Adapter<GridElementAdapter.SimpleViewHolder>{
private Context context;
private Deal[] mDeals;
public GridElementAdapter(Context context, Deal[] deals){
this.context = context;
this.mDeals = deals;
}
public static class SimpleViewHolder extends RecyclerView.ViewHolder {
public final ImageView dealImage;
public final TextView dealTitle;
public final TextView dealSubtitle;
public final TextView dealPrice;
public final TextView dealTime;
public final TextView dealDays;
public SimpleViewHolder(View view) {
super(view);
dealImage = (ImageView) view.findViewById(R.id.gridDealImageView);
dealTitle = (TextView) view.findViewById(R.id.gridTitleLabel);
dealSubtitle = (TextView) view.findViewById(R.id.gridSubtitleLabel);
dealPrice = (TextView) view.findViewById(R.id.gridPriceLabel);
dealTime = (TextView) view.findViewById(R.id.gridAvailableTimeLabel);
dealDays = (TextView) view.findViewById(R.id.gridAvailableDaysLabel);
}
}
@Override
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view = LayoutInflater.from(this.context).inflate(R.layout.deal_grid_item, parent, false);
return new SimpleViewHolder(view);
}
@Override
public void onBindViewHolder(SimpleViewHolder holder, final int position) {
String dealImageUrl = "http://api.cheapeat.com.au/deals/" + mDeals[position].getPhotoId() + "/photo";
Context context = holder.dealImage.getContext();
Picasso.with(context).load(dealImageUrl).placeholder(R.drawable.deal_image_placeholder).into(holder.dealImage);
holder.dealTitle.setText(mDeals[position].getName());
holder.dealPrice.setText(mDeals[position].getPriceData());
holder.dealSubtitle.setText(mDeals[position].getDescription());
holder.dealTime.setText(mDeals[position].getAvailabilityTime());
holder.dealDays.setText(mDeals[position].getFormattedAvailableDays(mDeals[position].getAvailabilityDay()));
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return this.mDeals.length;
}
は}だから私は最終的にこれを解決するために管理...今日のカップルのために、この1に貼付されています。私はHorizontalGridView
のためにLayoutManager
を設定していなかったことが分かります。具体的には、私は、アダプタを設定し活動に:私は、まだこの質問はなし正解で漂って見てきたよう
// Had this
horizontalGridView = (HorizontalGridView) findViewById(R.id.gridView);
GridElementAdapter adapter = newGridElementAdapter(VenueProfileActivity.this, mDeals);
horizontalGridView.setAdapter(adapter);
// This needed to be added
HorizontalGridView.LayoutManager layoutManager = new LinearLayoutManager(VenueProfileActivity.this, LinearLayoutManager.HORIZONTAL, false);
horizontalGridView.setLayoutManager(layoutManager);
horizontalGridView.setHasFixedSize(true);
うまくいけば、これは、いくつかの頭痛を節約できます。