android 识别表格行

发布于 2024-10-17 05:11:49 字数 287 浏览 2 评论 0原文

那么,有没有什么简单的方法来识别点击的表格行呢? 我有一个带有静态数据的表格布局,例如菜单。当用户单击任何表行时,我想启动指定的活动。 我已经用谷歌搜索了几个小时,但每个人似乎都使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

完美的未来在梦里 2024-10-24 05:11:49

如果您将 Activity 作为 ListView() 的扩展,并将选项放入列表中,您实际上可以重写该方法
公共无效onListItemClick(ListView父级,视图v,int位置,长id){
}
该方法的position属性是一个int,它指示您实际单击的行
这是一个我确信确实有效的解决方案,因此,如果您的表格布局不太复杂,我建议您制作一个列表并覆盖此方法!

好的,我会尝试另一种方法,因为这会导致您遇到其他问题问题,你可以做这样的事情:

onCreate()中:

firstTextVIew = (TextView) findViewById(R.id.firstText);

 firstTextView.setOnClickListener(this);

secondTextVIew = (TextView) findViewById(R.id.secondText);

 secondTextView.setOnClickListener(this);

onCreate()之后:

public void onClick(View v) {       

    /*make a list of cases for any text view, where __TextView is the name you gave to the textview when you made the getViewById() on the start of the activity*/
        if(v == firstTextView){         
            //start activity
        }
    if(v == secondTextView){        
            //start activity
        }   
    }

if you make your activity as an extension of ListView() and you put your options in a list you can actually override the method
public 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():

firstTextVIew = (TextView) findViewById(R.id.firstText);

 firstTextView.setOnClickListener(this);

secondTextVIew = (TextView) findViewById(R.id.secondText);

 secondTextView.setOnClickListener(this);

after the onCreate():

public void onClick(View v) {       

    /*make a list of cases for any text view, where __TextView is the name you gave to the textview when you made the getViewById() on the start of the activity*/
        if(v == firstTextView){         
            //start activity
        }
    if(v == secondTextView){        
            //start activity
        }   
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文