2011-12-28 53 views
0

上的LinearLayout視圖的ID我已經在LinearLayout中 許多意見(TextView的)我希望每個視圖id當我點擊查看 ,但我不想與每個視圖如何讓機器人

anyidea爲我setonclicklistener?

感謝

<LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/textViewd1" 
     android:layout_width="46dp" 
     android:layout_height="40dp" 
     android:background="#111111" 
     android:gravity="center"    
     android:text="SUN" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 
... 
many textviews 
... 

</LinearLayout> 
+0

爲什麼你不想使用有用的功能? – 2011-12-28 17:33:53

回答

5

屬性添加到每個視圖。 (您也應該明確地設置android:clickable="true"。)它可以節省輸入以爲所有這些設置樣式,特別是在許多TextView中共享某些其他屬性時。在你的活動中,定義一個方法:

public void methodNameUsedInOnClickAttribute(View view) { 
    int id = view.getId(); 
    // do something with ID 
} 
+0

非常感謝ted hopp,我明白了! – Pandy 2011-12-28 17:58:02