2011-11-30 4 views
1

Je sais que c'est une question qui a déjà été posée, mais je pense que je suis en train de faire le bon codage, et pourtant, je n'arrive pas à trouver le bon résultat. Voici mon code xml:LinearLayout non cliquable - Android

  <LinearLayout 
       android:id="@+id/directions_layout" 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:clickable="true"> 

       <ImageView android:src="@drawable/icon_directions" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:layout_marginLeft="5dp"/> 

       <TextView android:text="Directions" 
        android:textColor="@color/gray" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:layout_marginLeft="10dp"/> 

      </LinearLayout> 

Je ne sais pas si cela fait une différence ou non, mais le LinearLayout qui est le parent de celui ne correspond pas cliquable.

Voici où je mets le OnClickListener dans le code:

listener_layout = new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      Toast.makeText(v.getContext(), "hi", Toast.LENGTH_SHORT); 

     } 

    }; 
    call_layout = (LinearLayout) findViewById(R.id.call_layout); 
    call_layout.setOnClickListener(listener_layout); 

mais il me ... jamais mis le feu Toutes les suggestions?

Répondre

3
Toast.makeText(v.getContext(), "hi", Toast.LENGTH_SHORT); 

Vous n'avez pas appelé show() sur votre pain grillé, ce qui semble être votre auditeur ne se déclenche pas.

La ligne ci-dessus doit être:

Toast.makeText(v.getContext(), "hi", Toast.LENGTH_SHORT).show(); 
+0

wow ... Je me sens stupide. – coder

+6

Oui, parfois les points d'arrêt ressemblent à une approche plus fiable) – inazaruk

+0

@inazaruk: Puis-je +1 000 cela? – kcoppock