OnClicklistener not working for runtime views
I am displaying a table in my application which is created at runtime. I want to make all of its rows clickable. Here i used the code.
tableRow.addView(payeeNameText);
tableRow.addView(dueDateButton);
tableRow.setTag(1);
accountBillsTL.addView开发者_运维问答(tableRow);
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == (View)tableRow.getTag(1)){
System.out.println("Row Clicked");
}
}
but while clicked on the row nothing happens. no value print at LogCat. Please help. How can i make rows clickable with runtime views. thanks.
make your table row clickable and attach an onClick listener
tableRow.setClickable(true)
tableRow.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
System.out.println("Row Clicked with tag " + view.getTag());
}
})
Attention: view.getTag() does not have any argument! this returns just an object. You added an integer as a tag for this view so you can do something like this
if (((int) tableRow.getTag()) == 1) {
bla bla
}
You probably haven't added a listener for the "runtime view" you created.
yourView.setOnClickListener(this);
精彩评论