Android - Issue With OnClickListener and OnLongClickListener

I first inflate a Layout and later add a View to it using addView(). The layout has an OnLongClickListener attachted to it.

If I now add an OnClickListener to the inner view, the OnLongClickListener does no longer fire. How can I fix this?

Sample Code:

View someLayout =  getLayoutInflater().inflate(R.layout.some_layout, null);
someLayout.setOnLongClickListener(new OnLongClickListener() {

    public boolean onLongClick(View arg0) {
        return true;

TextView innerView = new TextView(this);

innerView.setOnClickListener(new OnClickListener() {    
        public void onClick(View arg0) {

((FrameLayout) view.findViewById(;


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:gravity="center" >



Any Ideas? This really seems rather odd.

Update: The same thing happens when I use an onTouchListener instead of an onLongClickListener, the OnClickListener in the inner view consumes all touch events.

Is this by design? What I want basically is the same functionality that the ContextMenu provides to a ListView.


A clickable View consumes all touch events and prevents them from being returned to the parent. Therefore the only way to register for long clicks on the whole area of a layout containing clickable Views is to also register the listener on every clickable View inside the layout.

Need Your Help

Google Play Services in emulator, implementing Google Plus login button etc

android google-plus google-play google-play-services

When integrating a Google Plus login button in an Android app, I'm observing some differences in how the button appears on an actual device and in the emulator. I am aware of the fact that the Google

Custom control structures in Scala?

scala functional-programming control-structure

There are a number of times I've run into a simple pattern when programming in Java or C++ for which a custom control structure could reduce the boilerplate within my code. It goes something like:...