简体   繁体   中英

Set ImageView Resource and TextView Text from Another Activity

I have a list view in an activity and when a row is selected I want to show another activity that contains an ImageView and a TextView. How can I set the image and text from the first activity? I'm guessing for the text I can use an extra with the intent.

intent.putExtra("data", bitmap)
intent.putExtra("your_string", strName);

You can recieve bitmap from another activity like this

Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("data");

It costs a lot of memory and is also slow.

If you want to pass it inbetween activities, you can store it in a file. That's more efficient.

There are multiple ways to sending data between Activities

  1. you can send image intent.putExtra("data", bitmap) and recieve it as @deniz suggested
  2. you can use Serializable to send data
  3. you can create Parcelable and send it to next Activity
  4. create a static Bitmap and get it in another Activity but it is not a good approach and against OOP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM