Android create dropdownlist without spinner component - android

I want to have a dropdownlist like this:
But i want to pop it up when you click a menu item. So spinner is not a necessary. Is there a standalone dropdownlist, or is it possible i trigger the spinner automatically?

You can do this a few ways:
Give your item a submenu by putting another <menu> element inside the <item> tag.
Handle the item click yourself and show a ListPopupWindow
Create a DialogFragment. Override onCreateDialog() and use an AlertDialog.Builder to create the dialog. Call one of the variations of setSingleChoiceItems() on the builder to set a list of single choice items to show in the content.
The first method is maybe the easiest since the selection will call back to your onOptionsItemSelected() method and you can easily handle it there, but the other options may be of interest to you as well.

If you want to show a dropdown list on an menu item click, you need to use the Spinner object.
Alternatively you can also use the Action bar with drop-down navigation : http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown

Related

How to create a small ListView by clicking on each items of a main ListView

I have a ListView in my app. and when user clicks on each item of it, I want a small ListView with 3 items appear to the user.Could any one suggests me How can I implement this small list?
Since you want to always show the same items, you could use a popup activity (a custom dialog) when the user clicks on the list.
The layout of this popup activity will only have a listview, populated in the onCreate() method.
If you want to use ListPopupWindow you can see this example:
Example on ListPopupWindow
To open another activity when an item is selected add something like this in the onItemClick method in ListPopupWindowAppActivity class:
Intent intent = new Intent(getApplicationContext(), AndroidFirstActivity.class);
startActivity(intent);
Keep in mind that ListPopupActivity is available since Api 11, so if you want to target earlier apis you can either use my first option (custom dialog) or the android.widget.PopupWindow. There are several examples for android.widget.PopupWindow, one can be found here:
Example of PopupWindow

How to dismiss Android Spinner drop down list programatically

I had a scenario where I am using spinner in my app. A made spinner drop down list to open up directly using "performclick()" method . The drop down list is opened. Is there a way in which I can close it automatically or click an item from drop down list automatically so that the drop down list is dismissed.
Borg8's answer is the only solution that works! Here is my version to add the spinner back.
if (spinner.getParent() == null){
parent.addView(spinner);
spinner.setLayoutParams(params);
spinner.forceLayout();
}
Spinner does not expose any means to close it explicitly. If setSelection() does not have that effect, then you may need to write your own widget that gives you more control, or avoid trying to do this.
This solution works for me and, for now, I don't see any reason why it will stop work.
If spinner is your spinner, then:
// get spinner layout and its parameters
ViewGroup parent = (ViewGroup)spinner.getParent();
ViewGroup.LayoutParams params = spinner.getLayoutParams();
// remove spinner from the layout - will dismiss its dropdown menu
parent.removeView(spinner);
// add spinner back and set same parameters
parent.addView(spinner);
spinner.setLayoutParams(params);
That's it

Selecting multiple items in ListView Android

I wish to select multiple ListView items and then share all of them. How can I go about it?
See the Awesome example here android-multiple-selection-listview
Well,
First you need to create OnItemClickListener(View v) in order to get clicks.
Then you can make a HashMap in order to preserve the items which are clicked.
You can also change the Background of the clicked item so the user will know which items are clicked.
Final thing you need is the action (button click - Share) which will pass through the HashMap and collect all clicked items. After that you can do with them what ever you want.
It looks like a huge work, but it's can easily divided into steps and you close them one by one... It actually quite simply.
I want that on the click of the option menu item in action bar, the listview's choice mode becomes multiple, which is easy to achieve. Simultaneously i want to inflate two options menu items namely "ok" and "cancel", so that once the user is done selecting some or all listview items, he can click on "ok" option menu to proceed.

Multiple Selection Spinner

I have a spinner that acts like a filter for searching among several categories. But the problem is that the spinner allows only one category to select from. Is there a way to obtain a multiple selection behavior for the spinner, or what other alternatives exists?
S spinner is designed to show one item at a time. You might get away by making a spinner of checkboxes, but it will be probably an awful user experience.
I would suggest you a ListView instead and CHOICE_MODE_MULTIPLE. You can add a listview to a dialog as shown in this answer: is it possible to create listview inside dialog?
Android provides Spinner widget which has functionality similar to drop-down list. But Spinner accepts single selection. so we select only one item at a time.so We can achieve multi-select feature using a custom Pop-up Window with a multi-select list.
Pop-up window is similar to Dialogs except that a pop-up window can be positioned.
When the drop-down button is clicked a list will be displayed(as drop-down), then you can select multiple values. The selected values will be displayed in a Text box above the list.
for reference you can prefer this link:
http://asnehal.wordpress.com/2012/04/03/multi-select-drop-down-list-in-android/

Android checkable submenu options

So I have a submenu that I have for an options menu item. I want a list of checkable entries that the user can select/deselect as many as they want. The only problem I can't solve is how to prevent the option menu from closing when one of the checkboxes is clicked. I saw the performShortcut has a FLAG_PERFORM_NO_CLOSE flag, but I'm not sure how to use that method. I've tried many things, but I'm confused on where the keyevent is supposed to come from or if this is even the right method I should be looking at.
So tl;dr: How do I prevent options menus/submenus from closing when an option is selected?
The way I would handle this is using the standard alert dialog class. In your menu handler, create an AlertDialog and pass an array of your options to the Builder.
The method you should pay attention to is AlertDialog.Builder.setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)
Pass an array to this method and put your submenu selection code in the ClickListener.

Categories

Resources