Created
February 25, 2011 10:59
-
-
Save anonymous/843642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
> | |
<TextView | |
android:id="@+id/selection" | |
android:layout_width="fill-parent" | |
android:layout_height="wrap_content" | |
/> | |
<Spinner android:id="@+id/spinner" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:drawSelectorOnTop="true" | |
/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java.. | |
public class SpinnerDemo extends Activity | |
implements AdapterView.OnItemSelectedListener { | |
TextView selection; | |
String[] items={"lorem", "ipsum", "dolor", "sit", "amet", | |
"consectetuer", "adipiscing", "elit", "morbi", "vel", | |
"ligula", "vitae", "arcu", "aliquet", "mollis", | |
"etiam", "vel", "erat", "placerat", "ante", | |
"porttitor", "sodales", "pellentesque", "augue", "purus"}; | |
@Override | |
public void onCreate(Bundle icicle) { | |
super.onCreate(icicle); | |
setContentView(R.layout.main); | |
selection=(TextView)findViewById(R.id.selection); | |
Spinner spin=(Spinner)findViewById(R.id.spinner); | |
spin.setOnItemSelectedListener(this); | |
ArrayAdapter<String> aa=new ArrayAdapter<String>(this, | |
android.R.layout.simple_spinner_item,items); | |
aa.setDropDownViewResource( | |
android.R.layout.simple_spinner_dropdown_item); | |
spin.setAdapter(aa); | |
} | |
public void onItemSelected(AdapterView<?> parent, | |
View v, int position, long id) { | |
selection.setText(items[position]); | |
} | |
public void onNothingSelected(AdapterView<?> parent) { | |
selection.setText(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment