Example usage for android.widget RelativeLayout setSaveEnabled

List of usage examples for android.widget RelativeLayout setSaveEnabled

Introduction

In this page you can find the example usage for android.widget RelativeLayout setSaveEnabled.

Prototype

public void setSaveEnabled(boolean enabled) 

Source Link

Document

Controls whether the saving of this view's state is enabled (that is, whether its #onSaveInstanceState method will be called).

Usage

From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java

/**
 * Dynamically creates radio buttons/* w w w  .  java 2  s  . co  m*/
 *
 * @param open311Attribute contains the open311 attributes
 */
private void createSingleValueList(Open311Attribute open311Attribute) {
    ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues();
    if (values != null && values.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(getActivity());
        RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_single_value_list_item,
                null, false);
        layout.setSaveEnabled(true);
        ((ImageView) layout.findViewById(R.id.ri_ic_radio))
                .setColorFilter(getResources().getColor(R.color.material_gray));

        Spannable word = new SpannableString(open311Attribute.getDescription());
        ((TextView) layout.findViewById(R.id.risvli_textView)).setText(word);

        if (open311Attribute.getRequired()) {
            Spannable wordTwo = new SpannableString(" *Required");
            wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ((TextView) layout.findViewById(R.id.risvli_textView)).append(wordTwo);
        }

        RadioGroup rg = (RadioGroup) layout.findViewById(R.id.risvli_radioGroup);
        rg.setOrientation(RadioGroup.VERTICAL);

        // Restore view state from attribute result hash map
        AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode());
        String entryValue = null;
        if (av != null) {
            entryValue = av.getSingleValue();
        }

        for (int i = 0; i < values.size(); i++) {
            LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i);
            RadioButton rb = new RadioButton(getActivity());
            rg.addView(rb); //the RadioButtons are added to the radioGroup instead of the layout
            String attributeKey = "";
            String attributeValue = "";
            for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) {
                if (Open311Attribute.NAME.equals(entry.getKey())) {
                    rb.setText(entry.getValue());
                    if (entryValue != null && entryValue.equalsIgnoreCase(entry.getValue())) {
                        rb.setChecked(true);
                    }
                    attributeKey = open311Attribute.getCode() + entry.getValue();
                } else if (Open311Attribute.KEY.equals(entry.getKey())) {
                    attributeValue = entry.getValue();
                }
            }
            mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue);
        }

        mInfoLayout.addView(layout);
        mDynamicAttributeUIMap.put(open311Attribute.getCode(), rg);
    }
}