Android, button doesn't work at all

This code presents my real problem ...

I am working on UI more complex.

I have a custom view that needs to have a button from its leftSide. What for? Because I have four options for this custom view. And these buttons are seen to create some intercalary look!

I have a simple layout that contains a button.

I had to pull it out of the parent layout, with the property clipChildren="false"

But the button doesn't respond to onClickListener

.

Of course I missed something, but what?

Animation click doesn't play at all ... Even Android song doesn't play ...

The java code has no effect there. Button ID button 2 works. Button id button doesn'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 method:

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();
    }
});

      

+3


source to share


1 answer


Try to revert the button back to its parent.

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



I suspect the problem is that something else that better claims the space that this button takes up is consuming the touch event.

+1


source







All Articles