2016-10-15 1 views
0
<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/relativeView" 
    android:background="@color/white" 
    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" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="40dp" 
     android:layout_below="@+id/today_date" 
     android:orientation="vertical" >  

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1.0" 

      android:orientation="horizontal" > 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_marginBottom="@dimen/activity_vertical_margin" 
       android:layout_marginEnd="@dimen/activity_vertical_margin" 
       android:id="@+id/ll1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/rectangle" 
       android:layout_weight="1.0" 
       /> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_marginBottom="@dimen/activity_vertical_margin" 
       android:layout_marginEnd="@dimen/activity_vertical_margin" 
       android:id="@+id/ll2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/rectangle" 
       android:layout_weight="1.0" 
       />  
     </LinearLayout> 

    <LinearLayout 
     android:weightSum="2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1.0" 
     android:orientation="horizontal" > 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_marginBottom="@dimen/activity_vertical_margin" 
      android:layout_marginEnd="@dimen/activity_vertical_margin" 
      android:id="@+id/ll3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/rectangle" 
      android:layout_weight="1.0" 
      /> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_marginBottom="@dimen/activity_vertical_margin" 
      android:layout_marginEnd="@dimen/activity_vertical_margin" 
      android:id="@+id/ll4" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/rectangle" 
      android:layout_weight="1.0" 
      >  
     </LinearLayout>  
    </LinearLayout>  
</LinearLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab_add_reminders" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_action_plus" 
     app:backgroundTint="#ffffff" 
     android:layout_gravity="bottom|end" /> 

</android.support.design.widget.CoordinatorLayout> 

Ainsi, chaque fois que j'appuie sur fab, l'activité de connexion de la disposition linéaire d'arrière-plan est également ouverte. Alors, quelqu'un peut-il me dire quel est le problème avec le code? Je ne sais pas pourquoi ce problème est survenu même lorsque le bouton FAB a été placé en dehors de la disposition linéaire.En appuyant sur le bouton d'action flottante, l'activité d'arrière-plan initie également

code Java: -

fab=(FloatingActionButton) findViewById(R.id.fab_add_reminders); 

     fab.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View view, MotionEvent motionEvent) { 

       //Set reminder dialog box appear 
       openDialogToAddReminder(); 
       return false; 
      } 
     }); 


nightLL.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Constants.SelectedBucket="Night"; 
       startActivity(new Intent(Reminders.this, ListReminders.class)); 
      } 
     }); 
+0

La question est un peu claire. Que se passe-t-il lorsque vous cliquez sur le FAB? – MohanadMohie

+0

son activité est également ouverte. @MohanadMohie –

+0

Je ne comprends toujours pas. L'activité n'est-elle pas déjà en cours? Le FAB ne fera que le code dans son onClick, alors qu'en est-il de votre code java? Peut-être que vous relancez l'activité? – MohanadMohie

Répondre

0

Vous utilisez un OnTouchListener sur la FloatingActionButton au lieu d'un OnClickListener, et vous êtes également à l'intérieur du faux retournerez OnTouchListener, ce qui signifie que la fab ne consomme pas l'événement tactile et passe à la vue suivante en dessous (nightLL).

Changer votre code à ceci:

fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      openDialogToAddReminder(); 
     } 
    }); 

Ou, si vous souhaitez utiliser un OnTouchListener pour toute autre raison, puis utilisez ce code:

fab.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       if (event.getAction() == MotionEvent.ACTION_DOWN) { 
        Toast.makeText(FabClickActivity.this, "FAB Touch.", Toast.LENGTH_SHORT).show(); 
       } 
       return true; 
      } 
     }); 
+0

merci l'homme .. vous me sauver .. –

+0

heureux d'être de l'aide. – MohanadMohie