android - put spinner in options menu -
how create options menu select languages below: languages: english, chinese (simplified) , bahasa malaysia
when english selected english values used when chinese (simplified) selected chinese (simplified)values used when bahasa malaysia selected bahasa malaysia value appear
first add below tag in layouts .xml file
<spinner android:id="@+id/my_spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawselectorontop="true"/>
now can define spinner must do, implementing onitemselectedlistener
simple example below:
package com.vimaltuts.android.spinner; import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.adapter; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import android.widget.arrayadapter; import android.widget.listview; import android.widget.spinner; import android.widget.textview; public class spinneractivity extends activity implements onitemselectedlistener { /** called when activity first created. */ private textview userselection; private static final string[] items={"android","bluetooth","chrome","docs","email", "facebook","google","hungary","iphone","korea","machintosh", "nokia","orkut","picasa","singapore","turkey","windows","youtube"}; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); userselection=(textview)findviewbyid(r.id.user_selection); spinner my_spin=(spinner)findviewbyid(r.id.my_spinner); my_spin.setonitemselectedlistener(this); arrayadapter aa=new arrayadapter(this, android.r.layout.simple_spinner_item,items); aa.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); my_spin.setadapter(aa); } @override public void onitemselected(adapterview arg0, view arg1, int pos, long arg3) { userselection.settext(items[pos]); } @override public void onnothingselected(adapterview arg0) { // todo auto-generated method stub userselection.settext(""); } }
hope helps!!!
Comments
Post a Comment