I think this is more of a fundamental java concept I am trying to grasp. Anyways, could someone explain to me how the
part of
works? From what i've read it looks like it is a method initializer? I don't really understand whats going on though. Why doesn't it look like anything ever calls the function onClick() in there?
Thanks for the help!
Code:
private OnClickListener btnListener = new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),
"Hello, Android Development World",
Toast.LENGTH_LONG).show();
}
};
Code:
package com.learntodev.HelloDroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.view.View;
public class HelloDroidActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button)findViewById(R.id.btnClickMe);
btn1.setOnClickListener(btnListener);
}
private OnClickListener btnListener = new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),
"Hello, Android Development World",
Toast.LENGTH_LONG).show();
}
};
}
Thanks for the help!
.