Note that there are some explanatory texts on larger screens.

plurals
  1. PORow Below - Making Three Spinners and Player Adds or Chooses Without Using the Same Name
    primarykey
    data
    text
    <p>Good morning fellas. This is me again, David Dimalanta. I'm here for a question. I need to create a program that if all three players got different names, the confirmation will say on the toast "Process complete." But instead, even all were not having the same name.</p> <p>Steps:</p> <ol> <li>Each player chooses a name from the spinner.</li> <li>The value is written onto the string.</li> <li>When button clicked, the process evaluates for similarity aliases (names).</li> <li>If similar, at least two, the toast message will say "Please specify a different username."</li> <li>If not, then it's complete.</li> </ol> <p>And, my activity name is "Player_3_at_Spinner_Menu.java". Here's my code for the first part under this class:</p> <pre><code>//Spinners for Players private Spinner spinner_1; private Spinner spinner_2; private Spinner spinner_3; //Button to Start private Button play_it; //For Displaying Text private String SUMMON_PICK_UP_1, SUMMON_PICK_UP_2, SUMMON_PICK_UP_3; private String cplayer_1, cplayer_2, cplayer_3; //Text Response from a Spinner public final static String EXTRA_MESSAGE_1 = "com.example.databasetestvertwo.MESSAGE1"; public final static String EXTRA_MESSAGE_2 = "com.example.databasetestvertwo.MESSAGE2"; public final static String EXTRA_MESSAGE_3 = "com.example.databasetestvertwo.MESSAGE3"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.players_3); //Searching for ID... (Button) play_it = (Button) findViewById(R.id.START_GAME); //Adding listener to the button(s). play_it.setOnClickListener(new trigger_happy_start()); //Call from the Database_Handler.class to call the database. Database_Handler db = new Database_Handler(getApplicationContext()); //Then, load the content and... loadSpinnerData(); } //Insert the value from the database into each of the spinners. private void loadSpinnerData() { //Initialize the spinners. spinner_1 = (Spinner) findViewById(R.id.player_1_spinner); spinner_2 = (Spinner) findViewById(R.id.player_2_spinner); spinner_3 = (Spinner) findViewById(R.id.player_3_spinner); Database_Handler db = new Database_Handler(getApplicationContext()); List&lt;String&gt; lables = db.getAllLabels(); //Creating an adapter for the spinner... ArrayAdapter&lt;String&gt; data_adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, lables); data_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //Inserts the spinners by a database. spinner_1.setAdapter(data_adapter); spinner_2.setAdapter(data_adapter); spinner_3.setAdapter(data_adapter); } //Action applied if a user chose this item. (Player 1) public class response_1 implements OnItemSelectedListener { public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { SUMMON_PICK_UP_1 = parent.getItemAtPosition(position).toString(); Toast.makeText(parent.getContext(), "You selected: " + SUMMON_PICK_UP_1, Toast.LENGTH_SHORT).show(); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { //Do nothing. I guess... } } //Action applied if a user chose this item. (Player 2) public class response_2 implements OnItemSelectedListener { public void onItemSelected(AdapterView&lt;?&gt; parent_2, View view, int position, long id) { SUMMON_PICK_UP_2 = parent_2.getItemAtPosition(position).toString(); Toast.makeText(parent_2.getContext(), "You selected: " + SUMMON_PICK_UP_2, Toast.LENGTH_SHORT).show(); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } } //Action applied if a user chose this item. (Player 3) public class response_3 implements OnItemSelectedListener { public void onItemSelected(AdapterView&lt;?&gt; parent_3, View view, int position, long id) { SUMMON_PICK_UP_3 = parent_3.getItemAtPosition(position).toString(); Toast.makeText(parent_3.getContext(), "You selected: " + SUMMON_PICK_UP_2, Toast.LENGTH_SHORT).show(); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } } </code></pre> <p>And, here's the code for checking if all, or at least two, players got the same name, the process warns them not to use the same name under this activity also. Here's my code:</p> <pre><code>private class trigger_happy_start implements OnClickListener { public void onClick(View v) { //Checks if the names assigned on each spinner have a the same name. if ( SUMMON_PICK_UP_1 == SUMMON_PICK_UP_2 || SUMMON_PICK_UP_1 == SUMMON_PICK_UP_3 || SUMMON_PICK_UP_2 == SUMMON_PICK_UP_3 ) { Toast.makeText(getApplicationContext(), "Please specify a different username.", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Process complete, idiot.", Toast.LENGTH_SHORT).show(); } } } </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