Note that there are some explanatory texts on larger screens.

plurals
  1. POIntent that checks onItemSelected and radio checked *
    primarykey
    data
    text
    <p>Newbie here again, thanks for al the help on my other questions. I have everything working, But my On click button I need to apply which radio id or array the spinner group pulled the array from and soi can forward to the correct page. I am mainly having a problem with the btn1 How to properly structure the if statements after the &amp; Any guidance as always is greatly appreciated.</p> <p>Found the solution!!! Posted at bottom!! String</p> <pre><code> &lt;string name="prov_picker"&gt;Select a Province&lt;/string&gt; &lt;string-array name="prov_array"&gt; &lt;item&gt;-- Select Province --&lt;/item&gt; &lt;item&gt;British Columbia&lt;/item&gt; &lt;item&gt;Alberta&lt;/item&gt; &lt;item&gt;Saskatchewan&lt;/item&gt; &lt;item&gt;Manitoba&lt;/item&gt; &lt;item&gt;Ontario&lt;/item&gt; &lt;item&gt;Quebec&lt;/item&gt; &lt;item&gt;New Brunswick&lt;/item&gt; &lt;item&gt;Nova Scotia&lt;/item&gt; &lt;item&gt;Newfoundland&lt;/item&gt; &lt;/string-array&gt; &lt;string-array name="prov1_array"&gt; &lt;item&gt;-- Select Province --&lt;/item&gt; &lt;item&gt;British Columbia&lt;/item&gt; &lt;item&gt;Alberta&lt;/item&gt; &lt;item&gt;Saskatchewan&lt;/item&gt; &lt;item&gt;Manitoba&lt;/item&gt; &lt;item&gt;Ontario&lt;/item&gt; &lt;item&gt;Quebec&lt;/item&gt; &lt;item&gt;New Brunswick&lt;/item&gt; &lt;item&gt;Nova Scotia&lt;/item&gt; &lt;item&gt;Newfoundland&lt;/item&gt; &lt;/string-array&gt; &lt;string name="radio1"&gt;Provincial&lt;/string&gt; &lt;string name="radio2"&gt;Federal&lt;/string&gt; Java mport android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.RadioGroup; import android.widget.SpinnerAdapter; import android.widget.Toast; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.Spinner; import android.view.View; public class CanProvselect extends Activity implements OnCheckedChangeListener { /** Called when the activity is first created. */ private RadioGroup RadioProvs; private Button btn1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.canprovselect); btn1 = (Button)findViewById(R.id.button1); RadioProvs = (RadioGroup) findViewById(R.id.rgProvs); RadioProvs.setOnCheckedChangeListener(this); } public void onCheckedChanged(RadioGroup group, int checkedId) { ArrayAdapter&lt;CharSequence&gt; adapter = null; final Spinner spinner = (Spinner) findViewById(R.id.spinner); switch (checkedId) { case R.id.radio_1 : adapter = ArrayAdapter.createFromResource( this, R.array.prov_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); //spinner.setOnItemSelectedListener(new OnItemSelected( // )); break; case R.id.radio_2 : adapter = ArrayAdapter.createFromResource( this, R.array.prov1_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); //spinner.setOnItemSelectedListener(new OnItemSelected( // )); break; } btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Spinner sp = (Spinner)findViewById(R.id.spinner); String spinnerString = null; spinnerString = sp.getSelectedItem().toString(); if (spinnerString.equalsIgnoreCase("British Columbia") &amp;&amp; R.id.equals("radio_1")){ Intent myIntent = new Intent (v.getContext(), ProvBC.class); startActivityForResult(myIntent, 0); } else if (spinnerString.equalsIgnoreCase("British Columbia") &amp;&amp; R.id.equals("radio_2")){ Intent myIntent = new Intent (v.getContext(), FederalProvBC.class); startActivityForResult(myIntent, 0); } } }); } } </code></pre> <p><strong>Solution</strong></p> <pre><code>btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Spinner sp = (Spinner)findViewById(R.id.spinner); String spinnerString = null; spinnerString = sp.getSelectedItem().toString(); if (spinnerString.equalsIgnoreCase("British Columbia") &amp;&amp; (checkedId == R.id.radio_1)){ Intent myIntent = new Intent (v.getContext(), ProvBC.class); startActivityForResult(myIntent, 0); } else if (spinnerString.equalsIgnoreCase("British Columbia") &amp;&amp; (checkedId == R.id.radio_2)){ Intent myIntent = new Intent (v.getContext(), FederalProvBC.class); startActivityForResult(myIntent, 0); } } }); </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