0

那么,有什么简单的方法可以识别点击的表格行吗?我有一个带有静态数据的表格布局,比如菜单。当用户单击任何表格行时,我想启动指定的活动。我用谷歌搜索了几个小时,但每个人似乎都使用 tablerows 文本属性中的视图来识别它,如果你翻译应用程序,这很糟糕。我试图找到 TableLayouit 的一些 getIndex 属性,但没有运气,views .getId 属性也没用。

我想解决方案是在每个 tablerow 上都有特定的 onclicklisteners 但这会产生很多(不必要的)代码,并且必须有更好的解决方案?

问候

4

1 回答 1

1

如果您将活动作为扩展ListView()并将您的选项放在列表中,您实际上可以覆盖方法 public void onListItemClick(ListView parent, View v, int position, long id) { } 并且该方法的位置属性是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
        }   
    }
于 2011-02-15T08:03:50.907 回答