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 8843613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:16:14+00:00 2026-06-14T11:16:14+00:00

I am building and android app and have created the login screen. The next

  • 0

I am building and android app and have created the login screen. The next screen will show the logged in user a set of options from which he has to choose one.

The second activity is started from the onPostExecute method of an AsyncTask using the startActivity(intent) code.

Intent intent = null;
intent = new Intent(context, DisplayMessageActivity.class);
    context.startActivity(intent);      

I am trying to build the UI for this screen using the .xml file activity_display_message.xml. The entry for this has been made to the manifest file.
Any of the layout attributes that I am specifying in this .xml file are not getting applied. Any help in this regard is highly appreciated. For example using the code below I am unable to get the background color that I have set. This works fine with the .xml that I have for my main activity.

The onCreate function for my DisplayMessageActivity class is

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_message);

    Intent intent = getIntent();
    String message = intent.getStringExtra(CommonStaticValues.EXTRA_MESSAGE);

    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    setContentView(textView);
}

The complete activity_display_message.xml file is

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="@color/background_color">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world"
    tools:context=".DisplayMessageActivity" />

</RelativeLayout>
  • 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-14T11:16:16+00:00Added an answer on June 14, 2026 at 11:16 am

    I see two problems here that are probably causing your problem. You first use setContentView like this:

    setContentView(R.layout.activity_display_message);
    

    That applied your XML file to the Activity, which is want you want. Later, you call it again with a TextView you created locally. If you wanted an Activity that consisted of one TextView on the screen, that’s one way to do it, but you don’t need it here because you have an XML definition of the Activity already.

    Secondly, your XML file’s TextView has no android:id. That’s used to reference the TextView from the code. So, modify your XML’s TextView to add that like this:

    <TextView
    android:id="@+id/txtView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world"
    tools:context=".DisplayMessageActivity" />
    

    Then, back in your onCreate, instead of constructing a new TextView with TextView textView = new TextView(this);, access the TextView from the XML you applied like this:

    TextView textView = (TextView) findViewById(R.id.txtView);
    

    Notice that the argument for findViewById is the id you create in the XML.

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

Sidebar

Related Questions

I'm building an Android app, and have set up a base DBObject class to
I am currently building an Android app where I will have to maintain two
I am building an Android app using phoneGap and I have successfully added the
I'm building an Android app and I need to have two different themes for
I am building an android app, and I want to be able to have
I am building an app for iPhone, android and Blackberry, and I have put
I'm building an Android app with OpenGL.I created 2 squares, each with their own
I thought I'd have a crack at building an Android app having not done
I am building an Android app that uses wifi. I have properly declared these
I'm building an android app where I basically implement a music player from a

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.