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??
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.
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<String> ar = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,spstr);
sp.setAdapter(ar);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> 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<?> 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;
}
}
XML
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
Logcat errors
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
resource
page2
page3