In an Android application, is it possible to open the spinner popup from a button click instead of pressing the actual spinner?
I have tried the following:
Button btnChange = (Button)findViewById(R.id.btnChange);
btnChange.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Spinner mySpinner = (Spinner) findViewById(R.id.sSpinner);
mySpinner.showContextMenu();
}
});
Try this one:
Spinner mySpinner = (Spinner) findViewById(R.id.sSpinner);
Button btnChange = (Button)findViewById(R.id.btnChange);
btnChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mySpinner.performClick();
}
});
Sorry for late answer - it's possible:
((Spinner) findViewById(R.id.mySpinner)).performClick();
It is possible, you just call it popup menu, not spinner.
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView .setOnClickListener(new OnClickListener(){
PopupMenu pum = new PopupMenu(this, findViewById(R.id.image));
pum.inflate(R.menu.image_chooser_popup);
pum.show();
});
}
Your spinner (or popup) items goes to R.menu.image_chooser_popup:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:title="take a picture"
android:titleCondensed="camera"
android:visible="true"
android:onClick="cameraIntent" />
<item
android:title="choose picture from gallery"
android:titleCondensed="string"
android:visible="true"
android:onClick="galleryIntent"/>
Hope this one helps some one. If you have any issues with my responce, please fill free to ask.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With