I'm using an adapter to load the items to a grid. then when the user select an item from the grid then it opens up the customizing screen. In that process I'm sending some data in the intent and later I can load the these in the customizing screen. Successfully I have loaded the other items other than the isVeg
item. Response I'mgetting for isVeg
, [false, true, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]
.
My problem is the way I have intented is correct or not. If it is correct how can I assign it to a ImageView.
adapter im using to send the data to next acitivty
@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);
final String strIsVag=isVeg.get(position);
final Bitmap mBitmap;
if (strIsVag.contains("true")) {
mBitmap = BitmapFactory.decodeResource(
this.context.getResources(), R.drawable.veg);
} else {
mBitmap = BitmapFactory.decodeResource(
this.context.getResources(), R.drawable.nonveg);
}
holder.tvImageIcon.setImageBitmap(mBitmap);
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));
next.putExtra("isVeg", mBitmap); //intent the image for selected item
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;
}
}
receiving the data in activity
final String description = getIntent().getStringExtra("description");
String imageUrl = getIntent().getStringExtra("imageUrl");
final String Strprice = getIntent().getStringExtra("price");
String mBitmap = getIntent().getStringExtra("isVeg"); // recives the item
setting the recivied data
final TextView descriptionTV = (TextView) findViewById(R.id.grid_text);
descriptionTV.setText(description);
final TextView priceTV = (TextView) findViewById(R.id.pasta_price);
priceTV.setText("PRICE RS " + Strprice);
ImageView imageView = (ImageView) findViewById(R.id.grid_image);
Picasso.with(this).load(imageUrl).into(imageView);
After you download a image from url below is your code-
after that store that bitmap in local storage. and pass path of that storage dir by intent and display it in other activity a you want. below is code for store image in local storage-
hope it will help you.
EDITED
create a file like -
I would suggest to convert Bitmap object to string and send to your desired activity like this:-
These this function write below ViewHolder class like this
then in the receiving activity convert the string back to bitmap to use it to the imageview like this:-
Assign where you want
Instead of sending Bitmap with intent send drawable id.make following changes in
getView
method:1. Get selected String from
isVeg
List:2. Receive data in activity
isVeg
as String:3. Set Image to ImageView according to strIsVag :