I want to show spinner element after click to TextView. I use the next code
final Spinner spin = new Spinner(context);
String[] tlt = {"Apple", "Orange", "Plum"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, tlt);
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
Log.v("itemNO", position+"");
}
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
spin.setAdapter(arrayAdapter);
txt = (TextView)findViewById(R.id.lang);
txt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
spin.performClick();
}
});
In my .xml file only TextView present (may be it's wrong?) After TextView click appear Spinner menu but when I choose some item nothing happen. It looks like setOnItemSelectedListener() does not work.
Have you any ideas? Thank you for answers!
Please check this example from the google developer site: http://developer.android.com/resources/tutorials/views/hello-spinner.html
You should add the Spinner to the xml file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.