如果您将活动作为扩展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
}
}