Hi in my application I need to add Some menu items. The problem is, one menu item should only display when the focus is on one of the listview items.
Simply one of the menu items should only display if the focus is on at one the of the listview items. When the focus is at anywhere else then should display only the other menu items except that. Other menu items will display always.
I can track the focus. I tried to run following code only when focus is on listview.
menu.add(0, Menu.FIRST, 0, "Add to favourite List"); [Problem: if I press menu button more than one time while focus there it creates new menu item each time when I press the menu button.]
I am inflating from xml menu and create others.
Can anyone guide me how to do this... Thanks
use onPrepareOptionsMenu method and clear all menu first using
menu.clear();
then add menu.
You could have a variable to keep track of whether that menu item was added or not.
Related
The attached UI is the calllog. What i am interested is that how the horizontal menu is implemented. When click on one list item, it appeared in one line under the list item.
In the earlier android, one click on list item, we can use Context menu popup menu to show the available action to do.
I am curious that it is using expandable list view concept?
I want to design like that when click on list item to show like this, but my layout would not be the same as this one. I want to put custom layout depending on the list item type. It may include button, textview, other widgets and the layout height will not be the list item height.
Can someone give some suggestion? Thanks a lot.
I have a listview with checkbox to select a row. Also I have a contextual action bar that pops up when an item is selected. My issue is that whenever I select an item , the list is pushed up and I see only the last items. If I have selected the first few items that were initially visible , those will be pushed up and can be seen only after scrolling down.This happens only for the first time when CAB is launched. If i select a second item the listview desnt scroll up or down as CAB is already visible and is not launched again
In my layout , for listview the following was set.
android:transcriptMode="alwaysScroll"
I removed this and it works now
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.
I have a ListView on my Android project, and when the item clicked, it will go to the "selected item detail info" activity. And when one of the item on hold, i want it to inflate or to pop up a context menu, it just like the one in some music player list.
I have no idea which event method that I should override to catch the onHold event of that listItem. Please somebody show me the way.
You should set on your ListView an OnItemLongClickListener.
If you are using ActionBar it would also be nice to set the ActionBar in ActionMode when an item is selected. For a quick tutorial for ActionMode you can check Vogella's List Tutorial.
In my android application I have a list view and some other buttons above the listview. I need to implement the functionality to add the selected item of the listview to my favourites list by creating a menu item.
I can create a menu item to click and add the functionality.
But it should only show the menu item if the focus is on any listview item and not when the focus is on any other button or anyItem. the menu item should only display when the focus is on any listview item and press the menu button.
Can Someone help me please.
Have you considered using a context menu instead of trying to modify the main menu? It seems like behavior might be more in line with the UI guidelines.