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 onclicklistener开发者_运维百科s on each tablerow but that will generate a lot of (unnecessary) code and there must be a better solution?
Regards
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
}
}
精彩评论