Android, Button don't working at all

This code represent my real issue...

I'm working on an U.I. more complexe.

I have a custom view that need to have a button out of his leftSide. Why? Because i have four of this custom view aside . And those button's view to create some intercalary view !

I have a simple layout that contains a button.

I had to make him out of his layout's parent, with the property clipChildren="false"

But the button don't response to the onClickListener.

I certainly miss something, but what?

The animation click isn't played at all... Even the Android's click's song isn't played...

The java code have no effect there.. The button's id button2 work. The button's id button don't work..

Here is my xml code.

<LinearLayout
    android:orientation="vertical"
    android:background="#0000FF"
    android:clipChildren="false"
    android:layout_marginLeft="80dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView
    android:textColor="#FF0"
    android:layout_marginLeft="-20dp"
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
    <Button
        android:id="@+id/button"
        android:layout_marginLeft="-80dp"
        android:layout_width="80dp"
        android:layout_height="80dp" />
    <Button
        android:id="@+id/button2"
        android:layout_width="80dp"
        android:layout_height="80dp" />
</LinearLayout>

and the onCreate Methode:

Button buton1 = (Button) rootView.findViewById(R.id.button);
buton1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.wtf("-----", "Click");
        Toast.makeText(getActivity(), "button1", Toast.LENGTH_LONG).show();
    }
});

Button buton2 = (Button) rootView.findViewById(R.id.button2);
buton2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(getActivity(), "button2", Toast.LENGTH_LONG).show();
    }
});

Upvotes: 3

Views: 233

Answers (1)

Tristan Burnside
Tristan Burnside

Reputation: 2566

Try putting the button back inside its parent.

If it works there, have a very long hard think about why you want this button to not live inside its parent. This is a bad idea almost all of the time as it breaks things (both practically and conceptually).

I would suspect the issue is that something else which has a better claim to the space the button is occupying is consuming the touch event.

Upvotes: 2

Related Questions