Hi, Im still very fresh in
java
help needed
the question is within the coding comment
Please kindly advise and correct me if i'm wrong... thanks
*****************************
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TryActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button pushButton = (Button)findViewById(R.id.push_button);
View.OnClickListener xx =
new View.OnClickListener()
{
// as i know , the
new keyword is for creating an object...
View.OnClickListener() is a constructor...
View.OnClickListener is a reference type
// the class
View.OnClickListener is an interface
// the problem is an interface doesn't allow any object instantiated from it and that's why interface automatically don't have any any constructor implement in it own class
// but why the
new View.OnClickListener() appear on above and creating an object with constructor... why???
// The API link is here
http://developer.android.com/reference/android/view/View.OnClickListener.html
public void onClick(View v)
{
Intent intent = new Intent(TryActivity.this, Try2Activity.class);
startActivity(intent);
}
};
pushButton.setOnClickListener(xx);
}
}