Clicking Children Item in Sliding Panel triggers parent first?

162 Views Asked by At

I am using sliding panel layout and in that i have ONE floating buttons.Now when i Click on the button the view Slides first and then i have to click again on button to perform action.

I want to perform action on only single click without the sliding movement of parent view.

Look at these images Look at 1 images look at this Here is my

XML

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SlidingPaneLayout           
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/Sliding"
android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:id="@+id/leftSide"
        android:background="#ef3"
        >

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/contact"
            android:background="@drawable/bg_key"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:background="@color/colorAccent"
    android:id="@+id/rightSide"
    android:layout_marginLeft="170dp"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="mini"
        android:focusable="false"
        app:srcCompat="@drawable/ic_menu_camera"
        android:id="@+id/call"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/message" />

</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>

here is my java code

SlidingPaneLayout sp;
 @Override
protected void onCreate(Bundle savedInstanceState)
{
    context = this;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    call = (FloatingActionButton) findViewById(R.id.call);

    sp = (SlidingPaneLayout) findViewById(R.id.Sliding);
    assert sp != null;
    sp.setPanelSlideListener(this);
    sp.setSliderFadeColor(Color.TRANSPARENT);
    sp.openPane();
    mList = new ArrayList<Contacts>();

    call.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            Log.e("CALL","CALL");
            try
            {
                if(number.isEmpty())
                {
                    Toast.makeText(context,"Please select contact first",Toast.LENGTH_SHORT).show();
                }
                else
                {
                    calling();
                    number=null;
                }

            }
            catch (Exception e)
            {
                e.printStackTrace();
                Toast.makeText(context,"This is not the valid contact",Toast.LENGTH_SHORT).show();
            }
        }
    });
}
1

There are 1 best solutions below

3
W4R10CK On

Use this code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v4.widget.SlidingPaneLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/Sliding"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:id="@+id/leftSide"
    android:background="#ef3"
    >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/contact"
        android:background="@drawable/bg_key"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:background="@color/colorAccent"
    android:id="@+id/rightSide"
    android:layout_marginLeft="170dp"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="mini"
        android:focusable="false"
        app:srcCompat="@drawable/ic_menu_camera"
        android:id="@+id/call"
        android:layout_alignParentTop="true" />
</RelativeLayout>
</RelativeLayout>