/** Shows the dialog box from which to select the sections */ @SuppressWarnings("unchecked") private void showSectionBox() { AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this); String title = mLanguageManager.getSelectSection(); builder.setTitle(title); // get it from the cache lstSection = (List<Section>) sectionCache.get(Global.SECTIONS); if (lstSection != null) { String[] sections = new String[lstSection.size()]; int i = 0; for (Section section : lstSection) { // stores the values into the array sections[i] = section.getSectionName().toString(); // checks if the section id is equal to the section id selected if (section .getSectionName() .toString() .equalsIgnoreCase(Prefs.getKey(Prefs.SECTION_NAME))) { selectionVal = i; } i++; } builder.setSingleChoiceItems(sections, selectionVal, this); builder.show(); } }
@Override public void onClick(DialogInterface dialog, int which) { // checks if this button is the ok button or not if (which == -1) { // if just ok is pressed then get the selected first value Section section = lstSection.get(selectionVal); sectionId = String.valueOf(section.getSectionId()); sectionName = section.getSectionName().toString(); Prefs.addKey(SettingsActivity.this, Prefs.SECTION_ID, sectionId); Prefs.addKey(SettingsActivity.this, Prefs.SECTION_NAME, sectionName); txtSectionSelection.setText(mLanguageManager.getSelectedSection() + ": " + sectionName); Global.logd(TAG + " section name: " + sectionName); txtSectionSelection.setTextColor(getResources().getColor(R.color.black)); dialog.dismiss(); } else if (which != -1) { isSectionSelectionChanged = true; selectionVal = which; Section section = lstSection.get(which); sectionId = String.valueOf(section.getSectionId()); sectionName = section.getSectionName().toString(); Log.i(TAG, "value of sectionId : " + sectionId); Prefs.addKey(SettingsActivity.this, Prefs.SECTION_ID, sectionId); Prefs.addKey(SettingsActivity.this, Prefs.SECTION_NAME, sectionName); refreshData(dialog); } }