Q:

How to pass an imagebutton as an argument to a function in android studio?

I have some imagebuttons in my application that the image they show is determined in the code (they are not supposed to respond to touch/click). How can I pass an imagebutton as an argument to a function in android studio? I am doing it like this:
private void compute_progress() {
   ...  
   progress_1();
   progress_2();
   ...
   progress_10();
   ...
}

private void progress_1() {
   ImageButton p1 = (ImageButton) findViewById( R.id.Progress1 );
   ...
   p1.setImageResource ( R.drawable.picture );
   ...
}

private void progress_2() {
   ImageButton p2 = (ImageButton) findViewById( R.id.Progress2 );
   ...
   p2.setImageResource ( R.drawable.picture );
   ...
}

...

private void progress_10() {
   ImageButton p10 = (ImageButton) findViewById( R.id.Progress10 );
   ...
   p10.setImageResource ( R.drawable.picture );
   ...
}

But I should and want to do it this way:
private void compute_progress() {
   ImageButton p1 = (ImageButton) findViewById( R.id.Progress1 );
   ImageButton p2 = (ImageButton) findViewById( R.id.Progress2 );
   ...
   ImageButton p10 = (ImageButton) findViewById( R.id.Progress10 );

   ...

   progress("imagebutton p1");
   progress("imagebutton p2");
   ...
   progress("imagebutton p10");

   ...
}

private void progress("receive ImageButton p") {
   ...
   p.setImageResource ( R.drawable.picture );
   ...
}

A:

Define the method you want to receive the ImageButton as a parameter like so:
private void progress(ImageButton imgButton) {
    imgButton.setImageResource(R.drawable.picture)
}

then when you need to call your method, call it like this (P1 being your ImageButton:
progress(p1)

