Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call method onClickListener

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

I've been looking for information and I see nothing that can help me.

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

like image 725
jlopez Avatar asked Jan 22 '13 13:01

jlopez


2 Answers

public void example(){

   img23.performClick();

}
like image 103
Archie.bpgc Avatar answered Oct 11 '22 16:10

Archie.bpgc


Why not create a function that will do the stuff that is required by the on click and then in your on click method call the function. Makes no sense to effectively duplicate the code once in a function and inside the onclick function.

like image 22
Boardy Avatar answered Oct 11 '22 16:10

Boardy