I am a beginner developer of an Android app and have a structure related question.
In my app I have a few screens with buttons that allow us to switch between these screens.
Right now I am setting up the SAME chunk of code with the button click listeners in each of these screen java file. I feel this is bulky and repetitive.
Is there a way to reference this chunk of code from a SEPARATE java file instead of duplicating it in each screen?
What direction should I look into? I feel it has something to do with inheritance of classes, but could you give an expert view on that?
Thank you so much! Anne
ADDED FROM HERE: LETS SAY I have the following code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
ImageButton goCreateBut = findViewById(R.id.createIcon);
goCreateBut.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(ListenRepeat.this, Recreate.class));
}
}
And this piece of code is repeated in each of 4 Activities. They all referencing the same button (in fact i have 4 more of similar buttons repeated this way). Is there anyway to cut on the repetitiveness? Thank you!