Android - How to avoid system's onClick? - android

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

Related

How to implement custom button with three text views in Android?

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.

Add or Remove ImageView dynamically

Is there any way to add or remove android imageview in UI dynamically ? I have 2 objects : List view and image view. I want to show each other dynamically without crashing each other.
when you want to show listView and hide ImageView, you can follow below code.
listView.setVisibility(View.VISIBLE); // showing listview
imageView.setVisibility(View.GONE); // hiding imageview
you can choose which one to show and which one to hide.
You can have both loaded from xml and then keep playing with View.VISIBILITY set it to GONE to hide and VISIBLE to make it vsible again.
So can either implement idea suggest by above.
Or for more cleaner code you can put elements in different layout and make the complete layout as visible or hidden whenever a certain event is being triggered!!
Hope this helps....!!!
You can put listview and imageview into FrameLayout and switch visibility

Clickable Image - Avoid touching another area

I am trying to make a clickable imageView. For the that I am using invisible buttons on it. But my question is when I click , I want to avoid touching on an empty area or other clickable part since the shape is not linear. How can I do that?
You should not use an invisible button to do that, you are just drawing several times the same pixels for nothing, and this will lead to poor performance.
What you can do is make your ImageView clickable (as #shkschneider told you) and use the ImageView's onClickListener methods to handle the onClick behaviour (the same way you would do with a button).
EDIT :
If I understood well, you're looking for a way to set several clickable areas among one ImageView. In that case, here is a good tutorial about it.
Don't use a Button, use an ImageView made clickable.
<ImageView android:clickable="true"

ListView: intercept click event to adjust selector

I have a ListView with my own adapter, who uses a own layout.
It's basically a horizontal LinearLayout with an Image and a TextView
I have specified a selector for my ListView, which changes the background color.
Furthermore I want to apply a ImageColorFilter on the ImageView. If the background changes.
Is there a simple way to do it with the build in ListView selector behavior or must I attach my own OnTouchListener to my LinearLayout?
I guess there are two possibilities:
Disbale the ListView selector and write your own OnTouchListener and
handle the touch events.
Use android:drawSelectorOnTop="true" to draw the selector on top of your View instead of drawing in the background.

Android Compound Control internal click events

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.

Categories

Resources