【发布时间】:2011-04-25 08:40:02
【问题描述】:
我正在用数据(字符串)填充 TableLayout(即行和列)。
当我单击一个单元格时,我希望该单元格中存储的数据显示在我的控制台中。
我该怎么做?除了查看ID还有其他方法吗?
【问题讨论】:
-
这个问题到底是关于什么的?苹果手机?航天飞机?
-
对不起,是关于Android开发的
标签: android tablelayout
我正在用数据(字符串)填充 TableLayout(即行和列)。
当我单击一个单元格时,我希望该单元格中存储的数据显示在我的控制台中。
我该怎么做?除了查看ID还有其他方法吗?
【问题讨论】:
标签: android tablelayout
如http://developer.android.com/resources/tutorials/views/hello-tablelayout.html 中所述,android 中没有 Column 或 TD(表数据)或 Cell 等效项。除非另有说明,否则每个元素都被视为一个单独的单元格。
有这个在我的,考虑到你没有指定你在你的行中使用什么样的视图,我猜它是一个按钮,你当然可以用这样的东西点击它:
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());
}
}
希望这会有所帮助。
【讨论】:
TableLayout 扩展了 LinearLayout,它没有 OnItemClickListener 方法。您将需要在子 Views 中实现 OnClickListener。
你可以做的是使用GridView,它实现了AdapterView,因此你可以使用OnItemClickListener
http://developer.android.com/resources/tutorials/views/hello-gridview.html
abstract void onItemClick(AdapterView<?> parent, View view, int position, long id)
单击此 AdapterView 中的项目时调用的回调方法。
【讨论】: