Ar Doe Ar Doe - 1 year ago 66
Android Question

Adding IF statement into each array index value in MulitSelectList preference

I'm trying to put an IF statement for each array index value, the value is from MultiSelectList preference. but I'm having problem on doing it, here is my code please help me.

public void displaySelectedDoa(View view) {

mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Set<String> selectionsDoa = mySharedPreferences.getStringSet("selectedDoaKey", null);
String[] selectedDoa = selectionsDoa.toArray(new String[]{});

if (selectedDoa == "0") { // if index number = 0
//do something at here
}
if (selectedDoa == "1") { // if index nuber = 1
//do here
}


}

this is my MultiSelectList from preference fragment

<MultiSelectListPreference
android:title="Select Doa"
android:summary="select your doa"
android:key="selectedDoaKey"
android:entries="@array/select_doa"
android:entryValues="@array/select_doa_value"/>

Answer Source

try this.

CharSequence[] selectedDoa = selectionsDoa.toArray(new String[]{});
    for (int i = 0; i < selectedDoa.length; i++){
        String index = selectedDoa[i].toString();
    }

 if (index.equals("string")){
//do here
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download