저는 2 주 이상이 작업에 어려움을 겪고 있습니다. 다중 선택 알림 대화를 지속하기 위해 sharedpreferenes 및 기타 '해킹'에 대한 모든 SO 질문이있었습니다. 하지만 불행히도 나는 여전히 그것을 작동시킬 수 없다.Persist AlertDialog 체크 옵션
누군가이 작품을 만드는 방법을 나에게 설명해 줄 수 있습니까? 내 다중 선택 경보 대화가 작동합니다. 하지만 난 여전히 선택한 항목을 저장할 수 없습니다 ..
내 코드 : 당신의 도움에 대한
public class TimelineSettings extends DialogFragment {
Context context;
final ArrayList selected_categories = new ArrayList();
final String[]items = {"Fourniture","Nourriture","Voyages","Habillement","Médias","Autres"};
TinyDB tinydb = new TinyDB(context);
private SharedPreferences sharedPreference;
private SharedPreferences.Editor sharedPrefEditor;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Set the dialog title
builder.setTitle("Choisissez vos paramètres")
.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexselected,
boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the selected items
selected_categories.add(indexselected);
} else if (selected_categories.contains(indexselected)) {
// Else, if the item is already in the array, remove it
selected_categories.remove(Integer.valueOf(indexselected));
}
}
})
// Set the action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
tinydb.putList("selected",selected_categories);
}
})
.setNegativeButton("Annuler", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
}
감사합니다.
추신 : 나는이 작품을 만드는 방법을 설명 할 수 있다면이 answer을 발견했습니다. 당신은 환경 설정에서 Integers
을 저장 한 다음 Strings
의 ArrayList
에 Integers
의 ArrayList
변환되기 때문에
당신은 대화를, 당신의 선택이 설정되지 않은 두 번째로 실행하면, 그것은 것입니다 : 여기
는 완전한 변경 및 코드인가? – joao2fast4u먼저 공유 환경 설정에 아무 것도 저장하지 않습니다. 또한 대화 상자를 작성할 때 공유 환경 설정에서 아무 것도 검색하지 않습니다. 빌드시 선택한 설정을 선택하는 것도 아닙니다. 그래서 지금까지 무엇을 시도 했습니까? db에서 정보를 검색하지 않습니다. DB의 상태도 저장하지 않습니다. – greenapps
@greenapps 먼저 공유 목록에 내 arraylist를 저장하려고 했으므로 arraylist를 문자열 집합으로 변환하려고 시도했지만 작동하지 않았습니다.이 tinydb 클래스를 사용하려고했지만 다시는 할 수 없었습니다. 그것을 작동하게하십시오. 내 문제는 정확히 어떻게 sharedprefs를 사용하여 선택한 선택의 배열을 저장하고 검색 할 수 있는지 정확히 알지 못한다는 것입니다. 어떻게 보여 주시겠습니까? – RidRoid