所以我有一個AlertDialog
這使得MultiChoiceItemsList
,是如下,如何到一個ArrayList傳遞到AlertDialog片段
public class CustomDayRepeatFragment extends DialogFragment {
public interface DayRepeatListner {
void onFinishDayRepeatListner(List<String> days);
}
//List to save the result
private ArrayList<String> selectedDays;
String weekdays[];
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
selectedDays = new ArrayList<>();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
weekdays = getResources().getStringArray(R.array.weekdays);
Log.d("In dialog", "Custom");
builder.setTitle("Select Days to Repeat")
.setMultiChoiceItems(weekdays, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked) {
selectedDays.add(weekdays[which]);
} else if (selectedDays.contains(weekdays[which])) {
selectedDays.remove(String.valueOf(weekdays[which]));
}
}
})
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for(int i = 0; i < selectedDays.size(); i++) {
Log.d("Selected Days", selectedDays.get(i));
}
}
});
return builder.create();
}
}
而且我從我的主要活動如下
CustomDayRepeatFragment dialog = new CustomDayRepeatFragment();
dialog.show(getSupportFragmentManager(), DIALOG_REPEAT_SETTING);
叫它但是,我想發送一個List<string>
到這個AlertDialog
,然後利用這個列表。
我無法弄清楚如何實現它。
感謝所有幫助
爲什麼不使用只是一個標準的制定者? – 2016-12-29 16:55:05
當你說發送一個清單你的意思是從alertDialog發送到您的活動權利? –
2016-12-29 16:56:27
@JawadLeWywadi從活動到alertDialog – Jagrati