Im getting a json response and from the im using of the item details to load in the menu grid, for that im using a adapter. at the moment i was able to load all the item details such as ImageURL , Description , Price. but i have the problem when loading the isVeg detail. isveg returns a true or false, then if the response is true then i have to load image1 and if the response is false then i have to laod the image2. where should check that n how to do it? where should i use the if condition if needed?
any help will be appreciated.
fragment class
if ((object.getString("MainCategoryID")).equals("1")
&& (object.getString("SubCategoryID")).equals("9")) {
Log.i("ImageURL ", object.getString("ImageURL"));
imageUrls.add(object.getString("ImageURL"));
Log.i("Description ", object.getString("Description"));
descriptions.add(object.getString("Description"));
Log.i("Price ", object.getString("Price"));
price.add(object.getString("Price"));
Log.i("IsVeg ", object.getString("IsVeg"));
isVeg.add(object.getString("IsVeg"));
}
}
CustomGridPizza adapter = new CustomGridPizza(getActivity(), descriptions,
imageUrls, price);
grid.setAdapter(adapter);
customgridpizzaadapter
public class CustomGridPasta extends BaseAdapter {
private Context context;
private final List<String> descriptions;
private final List<String> imageUrls;
private final List<String> price;
private final List<String> isVeg;
public CustomGridPasta(Context c, List<String> descriptions,
List<String> imageUrls, List<String> price, List<String> isVeg) {
this.context = c;
this.descriptions = descriptions;
this.imageUrls = imageUrls;
this.price = price;
this.isVeg = isVeg;
}
@Override
public int getCount() {
return descriptions.size();
}
@Override
public Object getItem(int position) {
return descriptions.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(
R.layout.pasta_single_item, parent, false);
holder.ivImage = (ImageView) convertView
.findViewById(R.id.grid_image);
holder.tvImageIcon = (ImageView) convertView
.findViewById(R.id.icon);
holder.tvHeader = (TextView) convertView
.findViewById(R.id.grid_text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvHeader.setText(descriptions.get(position));
Picasso.with(this.context).load(imageUrls.get(position))
.into(holder.ivImage);
if (isVeg.equals(true)) {
Bitmap mBitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.veg);
} else {
Bitmap mBitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.nonveg);
}
holder.tvImageIcon.setImageBitmap(mBitmap); //mBitmap cannot be resolved to a variable
Button customizePasta = (Button) convertView
.findViewById(R.id.bt_direct_customize);
customizePasta.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent next = new Intent(context, ActivityPastaCustomize.class);
next.putExtra("description", descriptions.get(position));
next.putExtra("imageUrl", imageUrls.get(position));
next.putExtra("price", price.get(position));
context.startActivity(next);
((Activity) context).overridePendingTransition(
R.anim.slide_in_right, R.anim.slide_out_left);
}
});
return convertView;
}
private class ViewHolder {
private TextView tvHeader;
private ImageView ivImage;
private ImageView tvImageIcon;
}
}
Aucun commentaire:
Enregistrer un commentaire