Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't view my TextView inside buttons onClickListener
    primarykey
    data
    text
    <p>Good morning everyone,</p> <p>I wanted to find out why my textview's won't show up in my app. I declared them inside a button's onClick method, so its like once the buttons been clicked, pop them up. Its basically for an "enter" type of button, where if the user enters the correct answer, display correct in the textview, otherwise wrong.</p> <pre><code>public void Easy12(){ Random rand = new Random(); int a = (int) rand.nextInt(100)+1; int b = (int) rand.nextInt(100)+1; final TextView tv = (TextView) findViewById(R.id.question_label); String aString = Integer.toString(a); String bString = Integer.toString(b); String display = aString + " + " + bString + " ="; tv.setText(display); final int c = a + b; final Button buttonhash = (Button) findViewById(R.id.keypad_hash); buttonhash.setOnClickListener(new OnClickListener(){ public void onClick(View v) { final EditText edittext = (EditText) findViewById(R.id.USERentry); if(edittext.getText().equals(c)){ final TextView answerLabel = (TextView) findViewById(R.id.rightwrong_label); answerLabel.setText(R.string.answer_correct); answerLabel.setTextColor(R.color.correct_color); } else { final TextView answerLabel = (TextView) findViewById(R.id.rightwrong_label); answerLabel.setText(R.string.answer_wrong); answerLabel.setTextColor(R.color.wrong_color); } } }); } </code></pre> <p>I had to make separate textviews that call the same textview because it wouldn't recognize them because of the brackets. This method is part of my Game class, which just displays an expression and checks to see whether the users answer is correct or not by pressing the a button on the screen. If anybody knows whats wrong please share. Thank you</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/question_label" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@+id/rightwrong_label" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;EditText android:id="@+id/USERentry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:textColor="@color/user_txt_color"/&gt; &lt;TableLayout.... </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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