Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get my difficulty level to load on my Android game
    primarykey
    data
    text
    <p>Basically I have to make a maths game with easy/medium/hard difficulties. I used the switch statement to achieve this which calls a method that deals with what to do in each difficulty.</p> <p>The problem is that I can't get my head around what this method with the switch statement should return, if anything, and how should I call it in the onCreate method. Also I don't know why, but the TextView in the getPuzzle method is giving me an error when I call the tv.setText method on it.</p> <pre><code>public class Game extends Activity { private static final String TAG = "Brain Training"; public static final String KEY_DIFFICULTY = "com.coursework.braintrain.difficulty"; public static final int DIFFICULTY_EASY = 0; public static final int DIFFICULTY_MEDIUM = 1; public static final int DIFFICULTY_HARD = 2; public static final int DIFFICULTY_GURU = 3; private int brain; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); int diff = getIntent().getIntExtra(KEY_DIFFICULTY, DIFFICULTY_EASY); setBrain(getPuzzle(diff)); getBrain(); setContentView(R.layout.gamelayout); final EditText edittext = (EditText) findViewById(R.id.USERentry); final Button button1 = (Button) findViewById(R.id.keypad_1); button1.setOnClickListener(new OnClickListener(){ public void onClick(View v) { // Perform action on clicks //String buttonText = (String) button.getText(); edittext.setText(edittext.getText() + "1"); //edittext.setText() = edittext.getText() + "1"; } }); //rest of the bottons... } public void Easy12(){ int a = (int) Math.random(); int b = (int) Math.random(); 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); } private int getPuzzle(int diff){ //TODO: Continue last game switch(diff){ case DIFFICULTY_HARD: break; case DIFFICULTY_MEDIUM: break; case DIFFICULTY_EASY: Easy12(); break; default: Easy12(); } //might require to return an array or something return diff; } public int getBrain() { return brain; } public void setBrain(int brain) { this.brain = brain; } } </code></pre> <p>Any advice would be appreciated.</p> <p>EDIT: Here's the xml file that goes along with it:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &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" android:text="Hello" /&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 android:id="@+id/keypad" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="*"&gt; &lt;TableRow&gt; &lt;Button android:id="@+id/keypad_1" android:text="1"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_2" android:text="2" android:onClick=""&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_3" android:text="3"&gt; &lt;/Button&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;Button android:id="@+id/keypad_4" android:text="4"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_5" android:text="5"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_6" android:text="6"&gt; &lt;/Button&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;Button android:id="@+id/keypad_7" android:text="7"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_8" android:text="8"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_9" android:text="9"&gt; &lt;/Button&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;Button android:id="@+id/keypad_0" android:text="0"&gt; &lt;/Button&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;Button android:id="@+id/keypad_del" android:text="del"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_minus" android:text="-"&gt; &lt;/Button&gt; &lt;Button android:id="@+id/keypad_hash" android:text="#"&gt; &lt;/Button&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    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.
 

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