我有一个自定义对话框,其中包含一个包含自定义项目的列表视图。它有2个textviews和一个复选框,当用户点击ok时,如何将检查的项目发送到打开自定义对话框的活动?提前谢谢。
答案 0 :(得分:1)
您可以使用回调接口。定义一个接口并在对话框中实现它。同样在您的活动中,将您的界面用作变量并将其发送到您的对话框。
答案 1 :(得分:0)
请参阅以下代码
AlertDialog.Builder builderSingle = new AlertDialog.Builder(
DialogActivity.this);
builderSingle.setIcon(R.drawable.ic_launcher);
builderSingle.setTitle("Select One Name:-");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
DialogActivity.this,
android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("Hardik");
arrayAdapter.add("Archit");
arrayAdapter.add("Jignesh");
arrayAdapter.add("Umang");
arrayAdapter.add("Gatti");
builderSingle.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String strName = arrayAdapter.getItem(which);
AlertDialog.Builder builderInner = new AlertDialog.Builder(
DialogActivity.this);
builderInner.setMessage(strName);
builderInner.setTitle("Your Selected Item is");
builderInner.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
builderInner.show();
}
});
builderSingle.show();