In my application generating dynamic text view. I want to add onclickListener to my text view. How can I do it please give me some hint. Here hard code for textview .
for (int i = 0; i < subCategory.length; i++) {
TextView tv = new TextView(this);
tv.setText(subCategory[i]);
tv.setId(i);
sCategoryLayout.addView(tv);
}
You need to call setOnClickListener(..) on TextView Instance. In the sample below we use anonymous inner class
It is not different from the one you do when you create text in xml:
this generic code for dynamically adding on click listner on any view or view group dynamically
first create a onclick listener:
and then, using
tv.setOnClickListener(listener)
to listen.here is code :
onclicklistener method :
hope useful to you.