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

  • Home
  • SEARCH
  • 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 9192669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:58:54+00:00 2026-06-17T20:58:54+00:00

I want to create a Enter your name-page (for the highscore) for my Android-game

  • 0

I want to create a “Enter your name”-page (for the highscore) for my Android-game but I’m experiencing some problems.
I want it to look like this:

You have reached (=enthst1)

………here’s the score…………..

points! (=enthst2)

Please type in your name to save your score! (= enthst3)

……..EditText for name…..

Back (=button) ………………. Enter (=button)

But I don’t seem to be able to add the score (int) to my ContentView!

Here’s the code:

Java in “onCreate”:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter_hs);

layo = new RelativeLayout(this);
MySco = new TextView(this) ;


Back = (Button)findViewById(R.id.enthsre1);
Back.setOnClickListener(this);

Enter =(Button)findViewById(R.id.enthsok1);
Enter.setOnClickListener(this);

Eingabe = (EditText) findViewById(R.id.editText1) ;

Texta = (TextView) findViewById(R.id.enthst1) ;
Textb = (TextView) findViewById(R.id.enthst2) ;
Textc = (TextView) findViewById(R.id.enthst3) ;

Intent intentk = getIntent();
kontro = intentk.getStringExtra("from").equals("MainActivity") ;

score = 0 ;

if(kontro == false){
score = punkteRechnen(tuleb, le0leb, le1leb, le2leb) ; //calculate the score
} else {
score = 10 ;
}

scoint = "" + score ;

MySco.setText(scoint) ;
MySco.setTextColor(Color.WHITE) ; 
MySco.setTextSize(20);

/*I know that this will throw me an IllegalStateException (the specified child already has a parent)
layo.addView(Texta) ;
layo.addView(MySco) ;
layo.addView(Textb) ;
layo.addView(Textc) ;
layo.addView(Eingabe) ;
layo.addView(Back) ;
layo.addView(Enter) ;
*/

XML:

<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/black"
    android:orientation="vertical"
    tools:context=".EnterHSActivity" >

    <TextView
        android:id="@+id/enthst1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/enthst1a"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        android:textSize="20sp"  />

    <TextView
        android:id="@+id/enthst2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_centerHorizontal="true"
        android:text="@string/enthst1b"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        android:textSize="20sp"  />

    <TextView
        android:id="@+id/enthst3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:layout_centerHorizontal="true"
        android:text="@string/enthst1c"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        android:textSize="18sp"  />

    <Button
        android:id="@+id/enthsre1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="100dp"
        android:text="@string/retour" />

    <Button
        android:id="@+id/enthsok1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="100dp"
        android:text="@string/allesklar" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/enthsre1"
        android:layout_alignRight="@+id/enthsok1"
        android:layout_below="@+id/enthst3"
        android:ems="10"
        android:inputType="text"
        android:textColor="@color/white"
        android:textColorHint="@color/white"
        android:textColorLink="@color/red" >

        <requestFocus />
    </EditText>

</RelativeLayout>

So, how do I add the score to my layout?

  • 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-17T20:58:56+00:00Added an answer on June 17, 2026 at 8:58 pm

    You should not add a view to a layout if it is already a child of that layout. When you call setcontentview your XML layout is inflated and all those views are created and added to your view hierarchy.

    I would add the MySco text view to your layout XML then call findviewbyid to get it. I would avoid dynamically adding views. You can always create a view that is hidden and then show it later to get a similar effect.

    Here is the modified / stripped down code for your onCreate method.

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_enter_hs);
    MySco = (TextView)findViewById(R.id.score);
    Intent intentk = getIntent();
    kontro = intentk.getStringExtra("from").equals("MainActivity") ;
    
    score = 0 ;
    
    if(kontro == false){
    score = punkteRechnen(tuleb, le0leb, le1leb, le2leb) ; //calculate the score
    } else {
    score = 10 ;
    }
    
    scoint = "" + score ;
    
    MySco.setText(scoint) ;
    MySco.setTextColor(Color.WHITE) ; 
    MySco.setTextSize(20);
    

    In your layout add this:

    <TextView
            android:id="@+id/score"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:textColorHint="@color/white"
            android:textSize="20sp"  />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create a page for my clients where they enter a number
It's a new app I want to build, but I would like some ideas,
I want to create a form in which if the User presses Enter the
I am trying to create a list where I want users to enter data
I want to create BASH file to create 50 users with while. But i
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want create an application with animate button? how can i do? after click
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =

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.