Android : ListView with Buttons -> OnItemClick do nothing - android

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})

Related

Android: Is it possible, to create a List with an arrayAdapter, that is clickable and has a checkbox for each list item?

I have a ListView that is clickable in a class(a new activity is opened, when you click on it), that extends ListActivity.This List get's filled through an arrayAdapter. Now I've tried to make the list checkable by implementing "android.R.layout.simple_list_item_single_choice" in the second Parameter of the ArrayAdapter Constructor. So the checkbox has arrived, but when I click on it, the activity is opened, but the checkbox isn't checked. To solve this issue, I`ve set the Parameters "focusable" and "focusableInTouchMode" of the ListLayout to false. But this hasn't worked either. I guess, that I have a problem with the focusable Parameter, but I think I have to change it anywhere else. But because the arrayAdapter takes away the work to define a layout for a single ListItem, I don't know where to do this. When I try to define a layout with a checkbox on my own, I get the error, that an ArrayAdapter requires the resource ID of the layout to be a TextView. So
Is it possible to solve this problem with an ArrayAdapter?
If yes, how can I solve it?
I appreciate your suggestions

ListView row with EditText, clickability, and context menu -- how to put it together?

I have a ListActivity-based activity that uses a context menu for the items. After adding an EditText to the row of a ListView, the context menu stopped working, and also the item does not react on a click. It seems that it is blocked somehow by the focus of the EditText. I can enter the EditText value, but I cannot get the earlier context menu, and I cannot start another activity via clicking the item.
I have possibly found the related comment that says:
Android doesn't allow to select list items that have focusable elements (buttons). Modify the button's xml attribute to:
android:focusable="false"
It should still be clickable, just won't gain focus...
... so I did the same for the EditText (I am not sure if the button case can be generalized for the EditText). Anyway, the item is clickable again, the context menu appears... However, the EditText part of the text stopped working now. (Actually, I did not implement the reaction to the EditText -- the keyboard simply does not appear.)
Is it possible to have the clickability of the list item and also make the EditText work the expected way?
I don't know if this would help you but it is a post I've found when I was trying to use a ListView with buttons inside.
ListView Tips & Tricks #4: Add Several Clickable Areas
Hope this helps.

Multiple Buttons and Listview

I need to create a layout with three Button and three ListView,when i click on first Button first Listview should be shown in the same activity and second button second ListView so on....
How is this possible?.Can anyone help me.
Have you considered using a Tab Layout? It's easy to use and you can have three tabs showing your list views, independently.
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
Add all of them to the same activity, then set the content of the three listviews. Add onClickListener() to each button and use View.Gone and View.Visible to control the visibility of the three ListViews. Or, like Hussain pointed out, just change the content of the single ListView
http://developer.android.com/reference/android/view/View.html#GONE

android listview

I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.

get a small list when clicked on a button

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.

Categories

Resources