I'm writing a custom compound control that extends RelativeLayout. Inside this component, there is an ImageView. I add a OnClickListener to this ImageView to animate it when the user clicks on it. But when I am in an activity using this control and I add a OnClickListener on the control, this listener is never called. It only works when I remove the other listener I have on the ImageView. Does anybody knows how to "propagate" the event to the other listeners when I catch it inside the control?
Thanks!
PS: I would also like to know if there is an existing control that looks like the icons on the Android desktop. Like an icon with text underneath.
Try setting one of these to true on your component:
android:clickable
android:focusable
android:focusableInTouchMode
android:longClickable
android:descendantFocusability
I had the same problem when I putted a button inside a ListView, I had to change one of the parameters to make the row be clickable, not only the button.
Related
I want to add three textViews in a single button.
I can do it using linearLayout as an XML file and then inflating it to my custom button class but somehow when I set click listener on this type of custom button it won't work.
I desire for a much better option, maybe extending the Android button class and then change it according to my requirement, but unable to inflate my button to my desired views.
Please assist me on how to do this.
Creating LinearLayout and setting style="#android:style/Widget.Button"
Did the trick for me.
You can design your layout with the three textviews as usual. For emulating click, set a StateListDrawable as the background of the root container. Put this in any layout (or use <include>) and attach a clickListener as usual.
You can simply use LinearLayout with 3 textview as its child and set click listener on it. No need to create custom button class. But I do not know exact requirement so need more details for creating custom button class.
I have a list view with a header. I want to have a clickable ToggleButton in the header. The button shows up okay, but I can't seem to make it clickable. Is there something special you have to do to make a listview header ToggleButton clickable?
What do you mean by "clickable"? Do you mean, the button isn't changing color when you touch it, or you just aren't getting the event when the button is clicked?
I'm guessing you just didn't set up an OnClickListener? You need to set up an OnClickListener either in your XML file, or in your Java file where you're setting up the view.
Here's the answer to a similar question.
I have a RelativeLayout that contains a few items: An ImageView and a few small TextView's.
Functionally I want to have the same on click event fire when anything in the RelativeLayout is clicked.
Visually I want to see the background of the RelativeLayout change so that it shows the entire layout (or "item") is being clicked.
My problem is that every time I click on the TextView's the on click doesn't propagate back to the parent view and so the background color doesn't change. How can I do this?
Ensuring you got no OnClickListener assigned to any of the childs of your RelativeLayout shall usually suffice for them to not receive clicks. Also check if you got no android:clickable="true" set by any chance for it. Then once you assing OnClickListener to your RelativeLayout it should get all the clicks.
for some items that has internal OnClickListener and you cannot easily remove their implementation of OnClickListener like SwitchComat, you can set
android:descendantFocusability="blocksDescendants"
on your parent layout. by adding this attribute to the parent view, non of the children will receive click events regardless of having onClickListener or not.
more on descendantFocusability
I Have a GrinView with costum Adapter that defines some ImageViews and set onClick event. When the user clicks the buttons it show some orange background, as the iimage bellow. How can I avoid this background display?
Try setting
android:background="#null"
in your layout xml.
Are you sure you are using a ImageView with onClickListener? If you are using an ImageButton, try changing it into a ImageView (that doesn't bring onClick-animation).
Cheers
I have a RelativeLayout to which I add buttons and set their onCLickListener to the current Activity where I handle their clicks.
Under a particular circumstance I need to set the RelativeLayout onClickListener also, but then once finished with the required clicking on the layout, I need to allow clicking on the buttons again. (i.e. clicking throug hthe layout)
If I set the layout's click listener to null I can no longer click either the layout or the buttons that are it's child views.
What am I doing wrong?
EDIT: I seem to have fixed it by setting;
relativeLayout.setClickable(false);
Have you tried:
relativeLayout.setOnClickListener(null);
relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
?