code setOnClickListener for multiple TextViews
Posted
by
user2870583
on Stack Overflow
See other posts from Stack Overflow
or by user2870583
Published on 2013-10-25T09:16:36Z
Indexed on
2013/10/25
9:54 UTC
Read the original article
Hit count: 132
android
I have 40+ TextViews
and I want to add click
events on them, but I try to do it "shortly" :
final GridLayout myGL;
myGL = (GridLayout) v0725.findViewById( R.id.tab1 );
for( int i = 0; i < myGL.getChildCount(); i++ )
if ( getResources().getResourceEntryName(((TextView) myGL.getChildAt(i)).getId()).indexOf("v")==0 ) {
((TextView) myGL.getChildAt(i)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v("edf", getResources().getResourceEntryName(((TextView) myGL.getChildAt(i)).getId()));
}
});
};
But Eclipse stops me on the Log.v
line, because i
should be final (but I can't)
any tips?
© Stack Overflow or respective owner