Is there any way in java to batch instantiate objects, initialize objects, and execute object methods?

for example:

ImageView imageview1;
ImageView imageview2;
ImageView imageview3;

imageview1=(ImageView)findViewById(R.id.main1);
imageview2=(ImageView)findViewById(R.id.main2);
imageview3=(ImageView)findViewById(R.id.main3);

imageView1.setVisibility(View.GONE);
imageView2.setVisibility(View.GONE);
imageView3.setVisibility(View.GONE);

if I use to generate multiple objects, how can I implement these in batches?


extract the common part into a method, and then call this method in a loop?


if you use android, you can try butterknife this open source library
to inject objects directly through annotations.

  

maybe you need dependency injection?

Menu