Note that there are some explanatory texts on larger screens.

plurals
  1. POSpinners item selected to go to a different page
    primarykey
    data
    text
    <p>I am having problems implementing a spinner into my code. Not quite sure how it works. But here is a brief idea of what I want to do. (Ex: click on the spinner and you have 2 options "page 2" and "page 3". So if you click on "page 2" it will go to page two with new content. Is there a way to accomplish that?? </p> <p>I also have image buttons to go to the next page and back. Just want to implement a spinner box so that you can navigate to different pages quicker.</p> <pre><code>public class AppActivity extends Activity implements OnTouchListener { private MediaPlayer mp; ImageButton button; ImageButton button3; ImageView imgView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final String[] spstr = getResources().getStringArray(R.array.spinnervalue); final Spinner sp = (Spinner)findViewById(R.id.spinner1); final ArrayAdapter&lt;String&gt; ar = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item,spstr); sp.setAdapter(ar); sp.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { String s=((TextView)view).getText().toString(); if(s.equals("page2")) startActivity(new Intent(view.getContext(),App2Activity.class)); if(s.equals("page3")) startActivity(new Intent(view.getContext(),App3Activity.class)); } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } }); } public void addListenerOnButton() { final Context context = this; button3 = (ImageButton) this.findViewById(R.id.imageButton5); button3.setOnTouchListener(this); mp = MediaPlayer.create(this, R.raw.vanilla_twilight); button = (ImageButton) findViewById(R.id.imageButton1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, App2Activity.class); startActivity(intent); } }); } @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.vanilla_twilight); mp.start(); mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); }; return true; } </code></pre> <p>} </p> <p>XML</p> <pre><code>&lt;Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /&gt; </code></pre> <p>Logcat errors</p> <p>05-22 01:32:40.058: E/SpannableStringBuilder(16206): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 05-22 01:32:40.058: E/SpannableStringBuilder(16206): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length</p> <p>resource page2 page3<br> </p>
    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.
 

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