2011-11-30 89 views
1

我知道這是一個以前已經問過的問題,但我認爲我正在做正確的編碼,但是我沒有得出正確的結果。在這裏我的XML代碼:LinearLayout不可點擊 - 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> 

我不知道這是否有差別或沒有,但所顯示的一個的父的LinearLayout無法點擊。

這裏是我設置OnClickListener代碼:

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

但它永遠不會被解僱......有什麼建議?

回答

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

你沒有給烤麪包打電話show(),這看起來好像你的聽衆不開火。

上面一行應該是:

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

哇......我覺得自己很蠢。 – coder

+6

是的,有時斷點看起來更可靠的方法) – inazaruk

+0

@inazaruk:我可以+1,000這個嗎? – kcoppock