android 识别表格行
那么,有没有什么简单的方法来识别点击的表格行呢? 我有一个带有静态数据的表格布局,例如菜单。当用户单击任何表行时,我想启动指定的活动。 我已经用谷歌搜索了几个小时,但每个人似乎都使用 tablerows 文本属性内的视图来识别它,如果您翻译应用程序,这很糟糕。我试图找到 TableLayouit 的一些 getIndex 属性,但没有成功,并且views .getId 属性毫无用处。
我想解决方案是在每个表行上都有特定的 onclicklisteners,但这会生成大量(不必要的)代码,并且必须有更好的解决方案吗?
问候
So, is there any easy way to identify the tablerow clicked?
I have a tablelayout with static data, like a menu. When the user click any tablerow I want to start the specified activity.
I've googled a couple of hours but everyone seem to use the view inside the tablerows text property to identify it, which sucks if you translate the app. I tried to find some getIndex property of the TableLayouit but no luck, and the views .getId property is useless.
I guess the solution is to have specific onclicklisteners on each tablerow but that will generate a lot of (unnecessary) code and there must be a better solution?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将 Activity 作为
ListView()
的扩展,并将选项放入列表中,您实际上可以重写该方法公共无效onListItemClick(ListView父级,视图v,int位置,长id){
}
该方法的position属性是一个int,它指示您实际单击的行
这是一个我确信确实有效的解决方案,因此,如果您的表格布局不太复杂,我建议您制作一个列表并覆盖此方法!
好的,我会尝试另一种方法,因为这会导致您遇到其他问题问题,你可以做这样的事情:
在
onCreate()
中:在
onCreate()
之后:if you make your activity as an extension of
ListView()
and you put your options in a list you can actually override the methodpublic void onListItemClick(ListView parent, View v, int position, long id) {
}
and the position attribute of that method is an int which indicates what row you actually click
this is a solution that i am sure actually works, so if your table layout is not too complicated i suggest you to make a list and override this method!
ok, I'll try another one since that one causes you other problems, you could make something like this:
in the
onCreate()
:after the
onCreate()
: