When doing android development, I often encounter codes like:
timer = new CountDownTimer(counter, 1000) {
public void onTick(long remainingTimeMillis) {
counter = remainingTimeMillis;
displayCount(counter);
}
public void onFinish() {
displayCount(0);
counter = 0;
timer = null;
beep.start();
}
};
or
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String s = (String) v.getTag();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, s, duration);
toast.show();
}
});
I've never seen such use in Java in other areas, could somebody explain what it means when calling a constructor and then define some other methods in it, which is like defining a class for me. And usually what are the circumstances where we need to use this kind of structure? Thanks a lot.