get a small list when clicked on a button - android

i have a image view and on top of it i have a button. now what i want is when i click on the button i should get a list of images on same Activity.actually i am trying to make a list in button,s onClick event. event gets fired but it does not show the list. anybody can have any idea how shall i achieve this i am also making my layout programmatically.
thanks alot

Without seeing some code it's hard to give a definite answer, but these are a few possibilities.
Create the listview together with the button, but set it's visibility to View.GONE or View.INVISIBLE. In the button's onClick method, set it to View.VISIBLE.
Alternatively, do the listview creation in the button's onClick (which I gather is what you're doing?), making sure you don't forget to add it to your layout. I have no idea why this does not work for you. Show some code or use the debugger to step through it and find out where it goes wrong.

Related

Change imageview for selected item in listview

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

Android: how to make only one item of ListView clickable?

I am working on a simple to-do list app, and on the main view I have a list of tasks with a checkmark aside to each, as the image below:
Upon clicking on the checkmark I want the respective task to be removed from the list. I tried to implement this as TextViews (for the tasks) and Buttons (for the checkmark), but I would need to know the number/position of the clicked checkmark (0,1,2 or 3) to remove the correct task from my array. Can I get this some how?
I also thought about implementing the tasks/checkmarks as a ListView, but then I would need to set a onItemClickListener only on the checkmark, and not on the task text. Is this possible?
Any other ideas? Thanks.
Checkbox has a tag property which you can use to set custom data like row number. Something like this should work,
checkbox.setTag(row_number);
So when you click on it, do something like
int rowNum = Integer.parseInt(checkbox.getTag());
removeTaskAt(rowNum);
If you're using a Custom Adapter, you can add a click listener on the check on getView, so the click is only on the checkbox and not on the full item.
The only problem with this is that the scroll may not work if you try to scroll by clicking on the checkbox.

Android: How do you remove the selection behavior from the Gallery?

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.

ListView clicklisteners

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.

Android : ListView with Buttons -> OnItemClick do nothing

My problem come from ListView. Without Buttons, the .setOnItemClickListener of the ListView work well. (start an Activity)
At time that I add Buttons into items of the ListView, Buttons are clickable but the items aren't more clickable...
I try to use myListView.setItemCanFocus(true); but it don't work...
Remove the focusable attribute from the Button would solve this problem. You could do that either in a layout xml file or java source code.
And one more tip, if you are using ImageButton instead of Button, you need setFocusable in your java code to make that work, cause the constructor of ImageButton would enabe this attribute after inflate from xml file.
It might be better to use an onTouch() callback for the clickable button within the listview. You should then be able to click.on both the list item and the button. See this question for some code (no need for touchDelegate).
The reason is button in your listview absorbs the onItemClickEvent.
A well explained tutorial is here
You can use this in .setOnItemClickListener of the ListView
view.findViewById(R.id.btn_id).setOnClickListener(new View.OnClickListener(){//your method})

Categories

Resources