Short answer: you definitely cannot do this in Java, but the compiler already told you that. You are trying to create two objects at once with links to each other, this is a problem with a chicken and an egg. Bottom line, you must first create ONE of them.
The offer consists of two steps:
.... final MyArrayAdapter aa = new MyArrayAdapter(); aa.initializeButtonClickListener(); ....
and then add the "initialize" method to the adapter.
public void initializeButtonClickListener(){ this.button.setOnClickListener(new View.OnClickListener() { @Override onClick(){ notifyDataSetChanged(); } }); }
Since this construction is somewhat complicated (i.e. more complicated than just calling the constructor), I would recommend then pulling these two lines into the MyArrayAdapter factory method and making the constructor private.
sharakan
source share