-1

I have Activity with DrawerLayout, I implements the Click ClickListener. The problem is when the DrawerLayer is open and user click on empty area on the darwerlayout, OnClick called as if he clicked the object behind it in the main layout. I checked the Id comes to onclick, and its the object behind the drawer.

public class MainActivity extends AppCompatActivity implements
       android.view.View.OnClickListener{
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         findViewById(R.id.resetThekir).setOnClickListener(this);
         // when User Clicks on the drawer that's already opened and above the image 
         //it calls the Onclick as if he clicks on the Image.
   }
   public void onClick(View v) {
        switch (v.getId()) {
        case R.id.addThkir:
        case R.id.currentThkirTxt:
        case R.id.thkirCount:
     }
}

XML

 <?xml version="1.0" encoding="utf-8"?>
 <android.support.v4.widget.DrawerLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

     <ImageView
            android:id="@+id/resetThkir"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="13dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/reset"
            android:contentDescription="@string/todo" />
</RelativeLayout>

<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:entries="@array/menuitems"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#CCCCCC"/>
 </android.support.v4.widget.DrawerLayout>
user93865
  • 147
  • 2
  • 15

1 Answers1

0

You need to add break after each case:

   public void onClick(View v) {
        switch (v.getId()) {
        case R.id.addThkir: addThkir() break;
        case R.id.currentThkirTxt: currentThikTxt() break;
        case R.id.thkirCount: thkirCount() break;
     }
Thommy
  • 5,070
  • 2
  • 28
  • 51
  • this is not the problem. I meant not to add break due to business rewuirments. The id return by v.getId() is the image where I clicked on the drawer not the image – user93865 Oct 01 '18 at 07:45