1
我的對話框是一個帶有一個標題和兩個按鈕的自定義佈局dialogbox_solution。 這裏是唯一的主線XML文件:編程如何在自定義對話框中設置自定義按鈕?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
<TextView
android:id="@+id/txtDiaMsg"
/>
<TableLayout
android:layout_below="@+id/txtDiaMsg">
<TableRow>
<Button
android:id="@+id/yesButton"
android:text=" YES "/>
<Button
android:id="@+id/noButton"
android:text=" NO "/>
</TableRow>
</TableLayout>
</RelativeLayout>
如何鏈接我的自定義按鈕,正面和負面的按鈕?
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
// do something here
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater li = getLayoutInflater();
View view = li.inflate(R.layout.dialogbox_solution, null);
builder.setView(view);
builder.show();
這對我的工作,THXü:) –
快樂幫... :) –