Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:27:25+00:00 2026-06-07T19:27:25+00:00

I have an Activity that has a main.xml with an ImageView. I then launch

  • 0

I have an Activity that has a main.xml with an ImageView.
I then launch an other activity and wand to show the same picture that is in the first activity.
My second activity’s layout is created programmatically with linearlayout (ll).
I then use the following:

    ImageView img = (ImageView) findViewById(R.drawable.logo);
    ll.addView(img);

    setContentView(ll);

but i get img to be null, It doesnt work if i change it to R.id.logo which is defined at main.xml

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:27:26+00:00Added an answer on June 7, 2026 at 7:27 pm

    First create a new imageview by doing ImageView img = new ImageView(this); Then set your drawable to any image you have in your “drawable” folders for example: img.setImageResource(R.drawable.my_image);

    Then you can add it to your linear layout like you do above and then setContentView.

    What you were doing above to findViewById does not make sense because you did not set content view. So just follow the setups i outlined above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which has a main activity that calls other activities on
Assume that we have 3 different activities. Each activity has its own XML file
I have a main activity, that holds the main menu. This menu has an
I have a simple Activity with its main.xml attached. main.xml has a custom layout
Here is the short version. I have a Bonus Activity that has 25 image
I have a application that has an activity that shows message logs. The thing
I have an Activity class which has an attribute that references an AsyncTask instance
I'm building an app that has a main Activity that takes advantage of the
I have a res/layout/main.xml including these elements and others: <some.package.MyCustomView android:id=@+id/foo (some other params)
I have an app that has 2 tabs. Each tab loads an xml file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.