I have a list view which has a couple of views within it, I have a textView and an ImageView.
What I need to do is, I want a person to be able to click just on the imageView without causing the onItemClicked function to be invoked, If the person clicks the ImageView, it should do something else, but if the person clicks away(apart from the imageview) from the imageView, then the onItemClicked is fired.
How do I do this?
It is kinda like, the listView on the android phone callLogs whereby, the green phone icon is somehow separated from the list but when clicked, it should know which listItem was selected and act accordingly.
I will appreciate the help. Thanks.
Here are some links for you are looking for. Advanced but if you stick with it and dont give up on this, you will learn a ton!!! Take a look:
Android: ListView elements with multiple clickable buttons
Android custom list item with nested widgets
use holder.imageView.setOnClickListener() in getView() method of adapter class.
Related
In my layout I have a button and a listview. How can I change the imageview of item I selected when the button is clicked. So lets say, I select 5 items, and after I click the button, images for those 5 items will be changed.
So I am confused what function I should use. Right now i used button.setOnClickListener but it seems wrong because only the very first item's imageview will be changed when button clicked. Should I use listview.setItemOnClickListener? Or is there any other way I can do this?
Thanks a lot!
Add a boolean to the data object in your adapter. Say you've got ArrayAdapter<MyDataObject>. Add some kind of "selected" field in the MyDataObject, and toggle it when you "select" the row.
Override getView in the adapter (you'll need a custom Adapter, btw. I'd just extend ArrayAdapter). When you render the row, if the "selected" field is true, show the "other" image.
When you click the button, call 'notifyDataSetChanged' on the adapter. The will cause the visible rows to refresh themselves (and call getView for each).
I think that'll work.
Since you only want images to change when you click the button, you'll need to have some kind of global boolean, so the getView won't show the image until the button has been clicked.
The complication here is, you have to deal with rows that may have been scrolled out of view, which don't have active views, but logically exist. It would be really hard to explain the concept here. I'd suggest some tutorials on ListView if you're not familiar with the recycling of row views.
You can used custom baseadapter for listview and setonclicklistener in the getView() method.... see tutorial here this is hope for help
You can use button click listener as well as on itemClickListener too but to make a image view in selected state in a list, you have to call setSelected method of imageview parent layout.
Please put a comment if you don't get me.
Thanks
I want my ListView to work something like the following:
When I press a button (probably from context-menu), I want the user to be able to select more then one item from ListView (probably using check-boxes), but those check-boxes should not be visible before that.
So, the point is, after the user presses a button (let's say "Delete more items"), the listview, should update itself, and appear on every row of the list, a checkbox should appear (allowing me to select the items ID to pass those to server).
How can I achieve that, without having to recreate the list from zero? (how to setVisibility ON, keeping the other content of the ListView as it is, and not doing another request to server).
PS. If you guys, have another better idea, on achieving the Delete More Items, would be much appreciated!
This is just an idea, haven't tried it myself: you build in a checkbox in your listitem layout. Normally, in the getView of your adapter, you set it invisible with
checkBox.setVisibility(8);
When you want to show them, you set some boolean
showBoxes
of your adapter to true, then in the getView oyu don't hide the checkboxes.
Then
notifyDataSetChanged
on the adapter.
Hope it's clear what I mean.
I am working on an android application that I like to do something like this picture below to a listview:
as you can see, there's a custom adapter for a list view that generates a list out of one of my classes.
I want to add a view like a Linearlayout or something under a Listview item after I clicked it.
how can I do that?
PS: where I have to put an onItemClickListener()? in my adapter's class or in my main page after onCreate() method?
PPS: in the picture, I meant SUBITEM FOR ITEM1... sorry...
You essentially want to do what this person does with a ViewStub, and implement an OnClickListener that is attached to each ListItem.
Please let me know if that is not clear or if you can't find a good example, and I'll see what I can do. :)
I really need horizontal scrolling in my app, so I overrode Gallery and I'm trying to do something with an OnItemSelectedListener, and a GestureDetector I'm calling from an OnTouchListener I've set on the Gallery. What I want is to remove the auto-selection of Gallery items as I scroll, but I want to be able to click an item to select it.
If I set an OnClick listener on a view that is populated in the adapter, the Gallery fails to scroll. Also, the OnItemClicked event is never called for the listener I set for that on the Gallery.
To remove selection from all items you should do this:
youGallery.setUnselectedAlpha(1);
Maybe my answer to this question will help you. It's something which wasn't intended to be ever realized...
For your case why dont you just use a HorizontalScrollView. Just put a linear layout inside and add as many imageview's as you need if your using images, or dynamicaly add it in java code.
This will elemenate the selection of gallery by default. This will be easier than trying to Override the Gallery widget default methods.
Why not you set some tag while you click on an item in the Gallery to select.
Now once again when you click after the item is selected just check for the tag that you had set, and based on the condition you can move to new screen and whatever task you want to perform.
But keep one thing in mind, you have to set the tag with every gallery item while building the gallery view.
I hope you will get what I want to say.
If still you have any problem then let me know.
I had the same scenario and I solved that.
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.