Here's the code:
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
if (id == DIALOG_SEARCH) {
dialog = new Dialog(this);
dialog.setContentView(R.layout.search_dialog_layout);
dialog.setTitle("Search Dialog");
Button button = (Button) dialog.findViewById(R.id.Button01);
final Button button2 = (Button) dialog.findViewById(R.id.Button02);
button2.setEnabled(false);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
button2.setEnabled(true);
}
});
}
return dialog;
}
How does the anonymous inner class (the OnClickListener) have access to the button2 variable? Its onClick method is called at some random time in the future when button
is clicked. In what context does this function run? How does it know about button2
? I'm just confused about the scoping and context here.