Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd dynamic text to RelativeLayout
    primarykey
    data
    text
    <p>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:</p> <blockquote> <p>You have reached (=enthst1)</p> <p>.........here’s the score..............</p> <p>points! (=enthst2)</p> <p>Please type in your name to save your score! (= enthst3)</p> <p>........EditText for name.....</p> <p>Back (=button) ................... Enter (=button)</p> </blockquote> <p>But I don’t seem to be able to add the score (int) to my ContentView!</p> <p>Here’s the code:</p> <p>Java in "onCreate":</p> <pre><code>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) ; */ </code></pre> <p>XML:</p> <pre><code>&lt;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" &gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;/RelativeLayout&gt; </code></pre> <p>So, how do I add the score to my layout?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload