Reputation: 2641
I have a button with id "ok" in my dialog.
Partial - Dialog Layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="8dp"
android:layout_below="@+id/licenseTypeLayout">
<Button
android:id="@+id/ok"
style="@style/agreement_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Ok"/>
</LinearLayout>
In activity:
Dialog dialog;
@OptionsItem(R.id.action_about)
boolean displayPopup() {
dialog = new Dialog(this);
dialog.setContentView(R.layout.about_dialog);
dialog.setTitle(R.string.app_name);
dialog.show();
Button btn=(Button)findViewById(R.id.ok);
//btn remains empty
return true;
}
How would I write onClick()
event for this button?
Upvotes: 0
Views: 1465
Reputation: 9700
To initialize the Button
, you need to use the Dialog
object
Button btn = (Button) dialog.findViewById(R.id.ok);
Then set OnClickListener
to the Button
using setOnClickListener()
as follows...
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//write your code here
}
});
Upvotes: 2
Reputation: 100
I would guess you make the method:
public void closeDialog(View v){ // Do what you want to do here (event handler)
}
?
Upvotes: 1