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

The Archive Base Latest Questions

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

Hey guys so I’m a bit new to Android programming and I have an

  • 0

Hey guys so I’m a bit new to Android programming and I have an issue and need help.

So I’ll use the first app that the official android site uses for training (http://developer.android.com/training/basics/firstapp/starting-activity.html)

and I’m confused about the creating second activity part. So after they’ve passed the intent they create a new TextView using java code (instead of XML) so I tried creating that TextView using the xml. I created a new TextView in the xml for the second activity and I give it an id like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".DisplayMessageActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" 
        android:id="@+id/new_Text"/>

</LinearLayout>

and here’s the java code for the second activity:

package com.example.myfirstapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

    public class DisplayMessageActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Get the message from the intent
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

        // Create the text view
        TextView textView = (TextView) findViewById(R.id.new_Text);
        textView.setTextSize(40);
        textView.setText(message);

        // Set the text view as the activity layout
        setContentView(textView);

        // Show the Up button in the action bar.
        // getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

All the code worked fine before I changed it. I changed

TextView textView = new TextView(this);

to:

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

but for some reason it can’t find new_Text and Eclipse only suggests id’s from my main.xml. Why is it that way? Is it because R.id.blabla only gets id’s from main.xml? So am I forced to make layouts using java code if they’re not going to be from 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-16T11:42:23+00:00Added an answer on June 16, 2026 at 11:42 am

    Alot of confusion in this post, but for starters:

    Each Activity that you intend to eventually be visable to the user gets its own XML layout. If you start a new Android project it will give u by default 1 XML layout located in the res>layout folder and 1 activity which will serve as your user facing visual activity by default.

    For your purposes , some easy ways to figure out if a activity is meant to be a “visual” activity include:

    *it extends activity or some other android superclass
    *it has a “onCreate method (useually located towards the top of the class)
    *inside that onCreate method there is a line of code called setContentView that looks something like this.

    setContentView(R.layout.httpex);

    The setContentView method is important bc its kind of like the glue between your activity and your xml layout. After R.layout.___ goes the name of the XML layout you would like to use.

    Only after youve set your content view to the approprate view can you link the elements or “views” from ur xml layout to your activity using the id you created. like this

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

    if you set the content view to httpex.xml , you can only link to views inside httpex.xml and ect…

    I have a spft spot for newbs bc ik what dicks this crowd can be to new blood for their ignorance , they forget how hard it was starting out and begin to feel all this stuff is common sense and obvious, but if i were you i would head over to thenewboston[dot]com and watch the entire series before posting to many questions like this around here so you dont get flamed on.

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

Sidebar

Related Questions

Hey guys, I have a little issue here. I need my users to be
Hey guys i am currently working on an android app that will allow me
Hey guys thanks for answering I'm really new to Android programming(I started today) and
Hey guys am having a bit of problems with my jQuery, I have all
Hey guys I have an array of dictionaries plist file that I am reading
Hey guys, I want to make a function loop over all elements that have
Hey guys, I have a problem (again). This time I am trying to use
Hey guys. I have a method that gets called each second which I want
Hey guys I am new to android development, I am currently making an application.The
Hey guys was hoping you could help me out I have a form, with

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.