I have a listview which contains names of people from my People class. I want to be able to mark multiple people and then delete marked for example.
I have read many questions and seen answers and I've decided I want to do it the following way for simplicity...
I just select the listItem, click on options menu and I select mark. Then a listener will set a private boolean in the person class, isMarked, to true, and then, to tell the user it is marked, a tick appears next to the listItem.
So the question is, is there a way to make an image appear and disappear in android?
EDIT: I have already implemented the options menu and selecting a person and selecting mark then making his/her marked variable true. What I basically need is an indicator to the user that that person is marked.
If what you want to do is have visual feedback for the item's status, then what you probably need is a custom view layout for the items in the ListView. When the list requests a view for the item (getView function) you can show/hide an image to indicate the item's status.
Check the documentation for Adapters, as there are a few other functions related to how this is done. You don't show in the question how you've set up the source of the ListView data.
However, as it seems that what you want to do is to select items and then perform actions on them, you should read on about contextual action bar (see the 'Using the contextual action bar'). Some more info in the menu's page, particularly in the 'Enabling batch contextual actions in a ListView or GridView' section. Selecting items one by one and using the menu to mark them seems like an non-android'y way of doing things.
So the question is, is there a way to make an image appear and disappear in android?
You need to get a reference to the view you want to show/hide and then use the following: http://developer.android.com/reference/android/view/View.html#setVisibility(int)
For example:
ImageView imageView = (ImageView) findViewById(R.id.myimageview);
if (isMarked) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.INVISIBLE);
Related
I am working on xamarin.forms. I am creating an app for android. In app I have a dropdown list. I am using Picker for it. I customized it to look like dropdown. Now I need to make the first Index item to nonselactable. Means user can not select the first item. If user click on it nothing should happen. But currently when user click on the first index dropdown gets collapsed.
One more thing that I have to add in dropdown is a Cross button at index 1. Means at index 1, on left side there will be Cross button and at center there will be text like Select item. And this whole row should not be selctable. If user click at cross button dropdown should collapsed.
Anyone have idea how I can do this?
You can use listview for dropdown and control its visibility as per need.I faced similar situation where I customized list view to enact dropdown.There is another thing I want to know about Picker.Does your picker accepts or adds string only or you could customize it to accept views or controls?
I'm working on a GridView with setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL). By default, rows are not getting highlighted (with the blue highlight you see on WhatsApp or Gallery apps), so I am wondering, does the Android API already takes care of highlighting the selected items and I am missing something (if so, what am I missing?) or do I have to take care of highlighting selected rows by myself (if so, how to highlight, not just change the background)?
Here's my code:
gridView.setOnItemClickListener(this);
gridView.setEmptyView(view.findViewById(R.id.empty));
gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
// multiChoiceModeListener is a subclass of AbsListView.MultiChoiceModeListener
// with no particular code on its abstracts methods.
gridView.setMultiChoiceModeListener(multiChoiceModeListener);
Use this for your ListItem background (XML layout)
android:background="?android:attr/activatedBackgroundIndicator"
It's basically only a selector, you can also build yourself: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/drawable/activated_background.xml
EDIT:
Given your comment, this solves it:
android:foreground="?android:attr/activatedBackgroundIndicator" with a FrameLayout
Also related question: How to set foreground attribute to other non FrameLayout view
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 am working on a UI where I have a list view. Each row has 2 information. One is Product name and the other is product ID stacked one over other. So each row has 2 lines of data.
What i want to do with this:
Once a user clicks on each row, it will further expand and show one input and one spinner. So it is basically for putting in Quantity and unit of measure.
Please let me know if this is achievable and if I can refer to some example.
What I need is more like
Taskos To Do List | Task List
https://play.google.com/store/apps/details?id=com.taskos&hl=en
All i need is that the category will not be expandable. Only the items will be expandable. All i need is an example of such app and then I can take it forward.
I think it could be done... you would need to put the extra widgets in your row layout, populate them and hide them upon list creation, then in your onListItemCLick you could unhide them.
Note I have no idea if this would work, but it seems reasonable that it might and it's what I would try and do to achieve the goal.
listView cannot be expanded. however you can use an expandablelistView
But the kind of functionality you want cannot be done this way(I guess.).
You can use
registerForContextMenu("your list View");
to register your list view
onCreateContextMenu
for the kind of action you want to be performed in your case its dialog with EditText and Spinner to have input from user
I'm writing an app and I have a ListView, which items are ImageView and TextView.
I'd like to determine whether user have clicked the icon or the text to handle diferrent actions for each case. I want to achieve similar effect like in stock contacts app.
First question: How to achieve the effect wich I've mentioned above?
Second question: In the stock contacts app when we click on a photo, a fancy bubble with some actions inside appears. How is it called? Where to get it from?
Thanks.
(edit)
ok, i've found something according to my second question:
How to make a fancy transparent menu like the "share menu" in Android gallery?
The answer on your first question: you should attach onClickListeners to each of your row's views in your Adapter's getView() method. This should do it.