Call onClickListener Method

This may seem like an absurd question, but I would like to be able to call the code associated with the event of pressing a certain button.

I was looking for information, and I see nothing that can help me.

An example of what I want:

final ImageView img23 = (ImageView) vTweets.findViewById(R.id.ImageView01); img23.setId(t); img23.setOnClickListener(new OnClickListener() { public void onClick(View v) { //I need to use this code without the user press the button// } }); public void example(){ //Here I need to use the code that is inside the onclick event// } 

thanks

+4
source share
2 answers
 public void example(){ img23.performClick(); } 
+15
source

Why not create a function that will make the material you want to click, and then call the function in the on click method. It makes no sense to effectively duplicate code once in a function and inside an onclick function.

+1
source

All Articles