2011-04-24 114 views
1

我使用數據(字符串)填充TableLayout(即行和列)。訪問TableLayout中的內容

當我點擊一個單元格時,我希望存儲在這個單元格中的數據顯示在我的控制檯中。

我該怎麼做?除了通過身份證以外還有其他方法嗎?

+0

這個問題到底是什麼?蘋果手機?航天飛機? – 2011-04-24 23:44:47

+0

什麼語言/環境? – ariel 2011-04-24 23:44:59

+0

對不起,這是關於Android的開發 – deimos1988 2011-04-25 00:06:12

回答

2

http://developer.android.com/resources/tutorials/views/hello-tablelayout.html所述,android中沒有Column或TD(Table Data)或Cell等價物。除非另有說明,否則每個元素都被視爲單個單元格。

在我的這個裏面,並且你沒有在你的行中指定你正在使用什麼樣的視圖,我想這是一個Button,你當然可以點擊這樣的東西:

Button b = (Button)findViewById(R.id.oneOfMyButtons); // You could create this "on the go" 
b.setOnClickListener(new View.OnClickListener{ 
    public void onClick(View v){ 
     System.out.println(v.getText()); 
    } 
} 

希望這會有所幫助。

+0

雖然我沒有使用按鈕,但TextViews,感謝您的幫助,我想出瞭如何從數據中獲取數據。非常感謝你! – deimos1988 2011-04-25 01:00:06

1

TableLayout延伸LinearLayout,它沒有OnItemClickListener方法。您需要在子女View s中實施OnClickListener

你可以做的反而是使用GridView,實現AdapterView,因此你可以使用OnItemClickListener

http://developer.android.com/resources/tutorials/views/hello-gridview.html

http://developer.android.com/reference/android/widget/AdapterView.html#setOnItemClickListener%28android.widget.AdapterView.OnItemClickListener%29

abstract void onItemClick(AdapterView<?> parent, View view, int position, long id) 

回調方法被調用時點擊此AdapterView中的項目。

+0

非常感謝您的回答,但我嘗試過使用GridView,但是這並不是我需要的應用程序。 – deimos1988 2011-04-25 00:58:33