Android onClick method doesn’t work on a custom view

I just had the same Problem – I created a custom view and when I registered a new Listener for it in the activity by calling v.setOnClickListener(new OnClickListener() {…}); the listener just did not get called. In my custom view I also overwrote the public boolean onTouchEvent(MotionEvent event) {…} method. The problem was that I … Read more

Android ViewGroup: what should I do in the onLayout() override?

In onLayout you need to call layout method on each child of this ViewGroup and provide desired position (relatively to parent) for them. You can check source code of FrameLayout (one of the simpliest subclasses of ViewGroup) to find out how it works. Although, if you don’t need any “special” layouting, you have other options: … Read more

Difference between setAlpha and setImageAlpha

ImageView.setAlpha(int) has been renamed to ImageView.setImageAlpha(int) to avoid confusion with the new method View.setAlpha(float) introduced in API level 11. View.setAlpha(float) is a general method available on all Views, including ImageView. It applies the specified opacity to the whole view. To achieve this, by default the system creates a temporary buffer (a hardware layer) where the … Read more