Example usage for android.widget RadioGroup getChildAt

List of usage examples for android.widget RadioGroup getChildAt

Introduction

In this page you can find the example usage for android.widget RadioGroup getChildAt.

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeRadioGroupFragment.java

@Nullable
@Override/*from w w w  .  j a va 2  s.c om*/
@SuppressWarnings("ConstantConditions")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_attribute_radiogroup, container, false);

    // Make sure the Fragment has found its arguments
    if (this.getArguments() == null) {
        throw new IllegalArgumentException(
                getClass().getName().concat(" cannot be " + "instantiated without arguments."));
    }

    final TextView subtitleTextView = (TextView) view.findViewById(R.id.subtitle);
    subtitleTextView.setText(getArguments().getString(ARG_SUBTITLE));

    final TextView summaryTextView = (TextView) view.findViewById(R.id.summary);
    summaryTextView.setText(getArguments().getString(ARG_SUMMARY));

    final RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radiogroup);
    for (String string : getArguments().getStringArrayList(ARG_ARRAY)) {
        final RadioButton radioButton = new RadioButton(getActivity());
        radioButton.setText(string);
        radioButton.setId(ViewUtils.generateViewId());
        radioGroup.addView(radioButton);
    }
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
                    .putInt(getArguments().getString(ARG_TITLE),
                            group.indexOfChild(group.findViewById(group.getCheckedRadioButtonId())))
                    .commit();
        }
    });

    // RadioGroup.check() is misleading, we must check the RadioButton manually
    ((RadioButton) radioGroup.getChildAt(PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getInt(getArguments().getString(ARG_TITLE), 0))).setChecked(true);

    return view;
}

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java

@Override
public void createAndAttachSelectQuestionRadioButton(Question question, LinearLayout sectionLinearLayout) {
    TextView textView = new TextView(getActivity());
    textView.setPadding(20, 0, 0, 0);//from  w  w  w. ja  v a 2  s  .c  o  m
    textView.setText(question.getLabel());

    RadioGroup radioGroup = new RadioGroup(getActivity());

    for (Answer answer : question.getQuestionOptions().getAnswers()) {
        RadioButton radioButton = new RadioButton(getActivity());
        radioButton.setText(answer.getLabel());
        radioGroup.addView(radioButton);
    }

    SelectOneField radioGroupField = new SelectOneField(question.getQuestionOptions().getAnswers(),
            question.getQuestionOptions().getConcept());

    LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    sectionLinearLayout.addView(textView);
    sectionLinearLayout.addView(radioGroup);

    sectionLinearLayout.setLayoutParams(linearLayoutParams);

    SelectOneField selectOneField = getSelectOneField(radioGroupField.getConcept());
    if (selectOneField != null) {
        if (selectOneField.getChosenAnswerPosition() != -1) {
            RadioButton radioButton = (RadioButton) radioGroup
                    .getChildAt(selectOneField.getChosenAnswerPosition());
            radioButton.setChecked(true);
        }
        setOnCheckedChangeListener(radioGroup, selectOneField);
    } else {
        setOnCheckedChangeListener(radioGroup, radioGroupField);
        selectOneFields.add(radioGroupField);
    }
}

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

/**
 * Creates open311 question and answer attributes to submit a report
 * Reads from dynamically created UI// w  w  w .  j  a v  a 2s  .c  o m
 *
 * @param serviceDescription contains attribute types
 * @return List of code value pair of attributes
 */
private List<Open311AttributePair> createOpen311Attributes(ServiceDescription serviceDescription) {
    List<Open311AttributePair> attributes = new ArrayList<>();

    for (Open311Attribute open311Attribute : serviceDescription.getAttributes()) {

        if (Boolean.valueOf(open311Attribute.getVariable())) {
            if (Open311DataType.STRING.equals(open311Attribute.getDatatype())
                    || Open311DataType.NUMBER.equals(open311Attribute.getDatatype())
                    || Open311DataType.DATETIME.equals(open311Attribute.getDatatype())) {
                EditText et = (EditText) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (et != null) {
                    attributes.add(new Open311AttributePair(open311Attribute.getCode(), et.getText().toString(),
                            open311Attribute.getDatatype()));
                }
            } else if (Open311DataType.SINGLEVALUELIST.equals(open311Attribute.getDatatype())) {
                RadioGroup rg = (RadioGroup) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (rg != null) {
                    int count = rg.getChildCount();
                    for (int i = 0; i < count; i++) {
                        RadioButton rb = (RadioButton) rg.getChildAt(i);
                        if (rb.isChecked()) {
                            String attributeKey = mOpen311AttributeKeyNameMap
                                    .get(open311Attribute.getCode() + rb.getText().toString());
                            attributes.add(new Open311AttributePair(open311Attribute.getCode(), attributeKey,
                                    open311Attribute.getDatatype()));
                            break;
                        }
                    }
                }
            } else if (Open311DataType.MULTIVALUELIST.equals(open311Attribute.getDatatype())) {
                LinearLayout ll = (LinearLayout) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (ll != null) {
                    int count = ll.getChildCount();
                    for (int i = 0; i < count; i++) {
                        CheckBox cb = (CheckBox) ll.getChildAt(i);
                        if (cb.isChecked()) {
                            String attributeKey = mOpen311AttributeKeyNameMap
                                    .get(open311Attribute.getCode() + cb.getText().toString());
                            attributes.add(new Open311AttributePair(open311Attribute.getCode(), attributeKey,
                                    open311Attribute.getDatatype()));
                        }
                    }
                }
            }
        }
    }
    return attributes;
}

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

/**
 * This method dynamically reads all user inputted the values from the screen and puts into a
 * list//from www.  ja  v  a2 s.c  o m
 *
 * @param serviceDescription displayed service description
 * @return List of attribute values
 */
private List<AttributeValue> createAttributeValues(ServiceDescription serviceDescription) {
    List<AttributeValue> values = new ArrayList<>();

    if (serviceDescription == null) {
        return values;
    }

    for (Open311Attribute open311Attribute : serviceDescription.getAttributes()) {
        if (Boolean.valueOf(open311Attribute.getVariable())) {
            if (Open311DataType.STRING.equals(open311Attribute.getDatatype())
                    || Open311DataType.NUMBER.equals(open311Attribute.getDatatype())
                    || Open311DataType.DATETIME.equals(open311Attribute.getDatatype())) {
                EditText et = (EditText) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (et != null) {
                    AttributeValue value = new AttributeValue(open311Attribute.getCode());
                    value.addValue(et.getText().toString());
                    values.add(value);
                }
            } else if (Open311DataType.SINGLEVALUELIST.equals(open311Attribute.getDatatype())) {
                RadioGroup rg = (RadioGroup) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (rg != null) {
                    int count = rg.getChildCount();
                    for (int i = 0; i < count; i++) {
                        RadioButton rb = (RadioButton) rg.getChildAt(i);
                        if (rb.isChecked()) {
                            AttributeValue value = new AttributeValue(open311Attribute.getCode());
                            value.addValue(rb.getText().toString());
                            values.add(value);
                            break;
                        }
                    }
                }
            } else if (Open311DataType.MULTIVALUELIST.equals(open311Attribute.getDatatype())) {
                LinearLayout ll = (LinearLayout) mDynamicAttributeUIMap.get(open311Attribute.getCode());
                if (ll != null) {
                    int count = ll.getChildCount();
                    AttributeValue value = new AttributeValue(open311Attribute.getCode());
                    for (int i = 0; i < count; i++) {
                        CheckBox cb = (CheckBox) ll.getChildAt(i);
                        if (cb.isChecked()) {
                            value.addValue(cb.getText().toString());
                        }
                    }
                    if (value.getValues().size() > 0)
                        values.add(value);
                }
            }
        }
    }
    return values;
}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

public void updatePageLayout() {
    String walkOrder = controller.getDirection();
    int lid = controller.getLayout();
    ((RadioGroup) findMyViewById(R.id.layoutGroup))
            .check(lid == 0 ? R.id.layout1 : lid == 1 ? R.id.layout2 : R.id.layout3);
    //((RadioGroup) findMyViewById(R.id.directionGroup)).check(did == 0 ? R.id.direction1 : did == 1 ? R.id.direction2 : R.id.direction3);

    RadioGroup group = (RadioGroup) findMyViewById(R.id.directionGroup);
    for (int i = 0; i < group.getChildCount(); i++) {
        View child = group.getChildAt(i);
        if (child instanceof universe.constellation.orion.viewer.android.RadioButton) {
            universe.constellation.orion.viewer.android.RadioButton button = (universe.constellation.orion.viewer.android.RadioButton) child;
            if (walkOrder.equals(button.getWalkOrder())) {
                group.check(button.getId());
            }//from   w ww. j  a  v a  2s .c o m
        }
    }
}

From source file:com.esri.squadleader.view.SquadLeaderActivity.java

public SquadLeaderActivity() throws SocketException {
    super();//  www  .  ja  va  2  s .c  om
    chemLightCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            for (int j = 0; j < group.getChildCount(); j++) {
                final ToggleButton view = (ToggleButton) group.getChildAt(j);
                view.setChecked(view.getId() == checkedId);
            }
        }
    };

    defaultOnSingleTapListener = createDefaultOnSingleTapListener();
}

From source file:com.google.code.twisty.Twisty.java

/** Have our activity manage and persist dialogs, showing and hiding them */
@Override//w ww  .j a v a2s.c  om
protected Dialog onCreateDialog(int id) {
    switch (id) {

    case DIALOG_ENTER_WRITEFILE:
        LayoutInflater factory = LayoutInflater.from(this);
        final View textEntryView = factory.inflate(R.layout.save_file_prompt, null);
        final EditText et = (EditText) textEntryView.findViewById(R.id.savefile_entry);
        return new AlertDialog.Builder(Twisty.this).setTitle("Write to file").setView(textEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        savefile_path = savegame_dir + "/" + et.getText().toString();
                        // Directly modify the message-object passed to us by the terp thread:
                        dialog_message.path = savefile_path;
                        // Wake up the terp thread again
                        synchronized (glkLayout) {
                            glkLayout.notify();
                        }
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // This makes op_save() fail.
                        dialog_message.path = "";
                        // Wake up the terp thread again
                        synchronized (glkLayout) {
                            glkLayout.notify();
                        }
                    }
                }).create();

    case DIALOG_ENTER_READFILE:
        restoredialog = new Dialog(Twisty.this);
        restoredialog.setContentView(R.layout.restore_file_prompt);
        restoredialog.setTitle("Read a file");
        android.widget.RadioGroup rg = (RadioGroup) restoredialog.findViewById(R.id.radiomenu);
        updateRestoreRadioButtons(rg);
        android.widget.Button okbutton = (Button) restoredialog.findViewById(R.id.restoreokbutton);
        okbutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                android.widget.RadioGroup rg = (RadioGroup) restoredialog.findViewById(R.id.radiomenu);
                int checkedid = rg.getCheckedRadioButtonId();
                if (rg.getChildCount() == 0) { // no saved games:  FAIL
                    savefile_path = "";
                } else if (checkedid == -1) { // no game selected
                    RadioButton firstbutton = (RadioButton) rg.getChildAt(0); // default to first game
                    savefile_path = savegame_dir + "/" + firstbutton.getText();
                } else {
                    RadioButton checkedbutton = (RadioButton) rg.findViewById(checkedid);
                    savefile_path = savegame_dir + "/" + checkedbutton.getText();
                }
                dismissDialog(DIALOG_ENTER_READFILE);
                // Return control to the z-machine thread
                dialog_message.path = savefile_path;
                synchronized (glkLayout) {
                    glkLayout.notify();
                }
            }
        });
        android.widget.Button cancelbutton = (Button) restoredialog.findViewById(R.id.restorecancelbutton);
        cancelbutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                dismissDialog(DIALOG_ENTER_READFILE);
                // Return control to the z-machine thread
                dialog_message.path = "";
                synchronized (glkLayout) {
                    glkLayout.notify();
                }
            }
        });
        return restoredialog;

    case DIALOG_CHOOSE_GAME:
        choosegamedialog = new Dialog(Twisty.this);
        choosegamedialog.setContentView(R.layout.choose_game_prompt);
        choosegamedialog.setTitle("Choose Game");
        android.widget.RadioGroup zrg = (RadioGroup) choosegamedialog.findViewById(R.id.game_radiomenu);
        updateGameRadioButtons(zrg);
        zrg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                dismissDialog(DIALOG_CHOOSE_GAME);
                String path = (String) game_paths.get(checkedId);
                if (path != null) {
                    stopTerp();
                    startTerp(path);
                }
            }
        });
        return choosegamedialog;

    case DIALOG_CANT_SAVE:
        return new AlertDialog.Builder(Twisty.this).setTitle("Cannot Access Games")
                .setMessage("Twisty Games folder is not available on external media.")
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // A path of "" makes op_save() fail.
                        dialog_message.path = "";
                        // Wake up the terp thread again
                        synchronized (glkLayout) {
                            glkLayout.notify();
                        }
                    }
                }).create();

    case DIALOG_NO_SDCARD:
        return new AlertDialog.Builder(Twisty.this).setTitle("No External Media")
                .setMessage("Cannot find sdcard or other media.")
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // do nothing
                    }
                }).create();
    }
    return null;
}

From source file:sliding_tab.SlidingTabs.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public View getView(final int position, View convertView, ViewGroup viewGroup) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.event_attending_list_item, null);

    TextView name = (TextView) convertView.findViewById(R.id.tv_ea_list_item);
    final RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup);
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            ArrayList<String>[] dbResult = Helper.getFriends_From_Event(Event_ID);
            switch (radioGroup.getCheckedRadioButtonId()) {
            case R.id.rb_ea_list_yes: {
                Update_Attending(dbResult, Constants.Yes, position);
                break;
            }/*from  w  w w.  ja va2  s.c om*/
            case R.id.rb_ea_list_maybe: {
                Update_Attending(dbResult, Constants.Maybe, position);
                break;
            }
            case R.id.rb_ea_list_no: {
                Update_Attending(dbResult, Constants.No, position);
                break;
            }
            }
        }
    });
    ArrayList<String>[] dbResult = Helper.getFriends_From_Event(Event_ID);
    //name.setText(dbResult[1].get(position));
    name.setText(Helper.getNickname(dbResult[1].get(position)));
    switch (dbResult[2].get(position)) {
    case Constants.Yes: {
        radioGroup.check(R.id.rb_ea_list_yes);
        break;
    }
    case Constants.Maybe: {
        radioGroup.check(R.id.rb_ea_list_maybe);
        break;
    }
    case Constants.No: {
        radioGroup.check(R.id.rb_ea_list_no);
        break;
    }
    default: {
        break;
    }
    }
    if (!dbResult[1].get(position).equals(Constants.MY_User_ID)) {
        for (int i = 0; i < radioGroup.getChildCount(); i++) {
            radioGroup.getChildAt(i).setEnabled(false);
        }
    }

    return convertView;
}

From source file:com.wanikani.androidnotifier.ItemsFragment.java

/**
 * Builds the GUI and create the default item listing. Which is
 * by item type, sorted by time.// w  w  w. j a v  a2s  .co m
 * @param inflater the inflater
 * @param container the parent view
 * @param savedInstance an (unused) bundle
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    RadioGroup rg;
    ImageButton btn;
    View sview;
    int i;

    super.onCreateView(inflater, container, bundle);

    scheduleRefresh();

    parent = inflater.inflate(R.layout.items, container, false);

    lview = (ListView) parent.findViewById(R.id.lv_levels);
    lview.setAdapter(lad);
    lview.setOnItemClickListener(lcl);

    iview = (ListView) parent.findViewById(R.id.lv_items);
    iview.setAdapter(iad);

    sview = parent.findViewById(R.id.it_search_win);
    isd = new ItemSearchDialog(sview, iss, fmap.get(filterType), iad);

    btn = (ImageButton) parent.findViewById(R.id.btn_item_filter);
    btn.setOnClickListener(mpl);
    btn = (ImageButton) parent.findViewById(R.id.btn_item_sort);
    btn.setOnClickListener(mpl);
    btn = (ImageButton) parent.findViewById(R.id.btn_item_view);
    btn.setOnClickListener(mpl);
    btn = (ImageButton) parent.findViewById(R.id.btn_item_search);
    btn.setOnClickListener(mpl);

    rg = (RadioGroup) parent.findViewById(R.id.rg_filter);
    for (i = 0; i < rg.getChildCount(); i++)
        rg.getChildAt(i).setOnClickListener(rgl);
    rg.check(R.id.btn_filter_none);

    rg = (RadioGroup) parent.findViewById(R.id.rg_order);
    for (i = 0; i < rg.getChildCount(); i++)
        rg.getChildAt(i).setOnClickListener(rgl);
    rg.check(R.id.btn_sort_type);

    enableSorting(true, true, true, true);

    return parent;
}

From source file:com.aware.ui.ESM_UI.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    //      getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE);
    //      getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    //        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    //        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    builder = new AlertDialog.Builder(getActivity());
    inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

    TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0
            ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG)
            : TAG;//from w  ww  . j a  va 2  s . c o  m

    Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null,
            ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1");
    if (visible_esm != null && visible_esm.moveToFirst()) {
        esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID));

        //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation
        ContentValues update_state = new ContentValues();
        update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE);
        getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state,
                ESM_Data._ID + "=" + esm_id, null);

        esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE));
        expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD));

        builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE)));

        View ui = null;
        switch (esm_type) {
        case ESM.TYPE_ESM_TEXT:
            ui = inflater.inflate(R.layout.esm_text, null);
            break;
        case ESM.TYPE_ESM_RADIO:
            ui = inflater.inflate(R.layout.esm_radio, null);
            break;
        case ESM.TYPE_ESM_CHECKBOX:
            ui = inflater.inflate(R.layout.esm_checkbox, null);
            break;
        case ESM.TYPE_ESM_LIKERT:
            ui = inflater.inflate(R.layout.esm_likert, null);
            break;
        case ESM.TYPE_ESM_QUICK_ANSWERS:
            ui = inflater.inflate(R.layout.esm_quick, null);
            break;
        }

        final View layout = ui;
        builder.setView(layout);
        current_dialog = builder.create();
        sContext = current_dialog.getContext();

        TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions);
        esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS)));

        switch (esm_type) {
        case ESM.TYPE_ESM_TEXT:
            final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback);
            Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel);
            cancel_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0);
                    current_dialog.cancel();
                }
            });
            Button submit_text = (Button) layout.findViewById(R.id.esm_submit);
            submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
            submit_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0);

                    if (expires_seconds > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);

                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.ANSWER, feedback.getText().toString());
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                    sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                            ESM_Data._ID + "=" + esm_id, null);

                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    getActivity().sendBroadcast(answer);

                    if (Aware.DEBUG)
                        Log.d(TAG, "Answer:" + rowData.toString());

                    current_dialog.dismiss();
                }
            });
            break;
        case ESM.TYPE_ESM_RADIO:
            try {
                final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio);
                final JSONArray radios = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS)));

                for (int i = 0; i < radios.length(); i++) {
                    final RadioButton radioOption = new RadioButton(getActivity());
                    radioOption.setId(i);
                    radioOption.setText(radios.getString(i));
                    radioOptions.addView(radioOption);

                    if (radios.getString(i).equals("Other")) {
                        radioOption.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                final Dialog editOther = new Dialog(getActivity());
                                editOther.setTitle("Can you be more specific, please?");
                                editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                editOther.getWindow().setGravity(Gravity.TOP);
                                editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT,
                                        LayoutParams.WRAP_CONTENT);

                                LinearLayout editor = new LinearLayout(getActivity());
                                editor.setOrientation(LinearLayout.VERTICAL);

                                editOther.setContentView(editor);
                                editOther.show();

                                final EditText otherText = new EditText(getActivity());
                                editor.addView(otherText);

                                Button confirm = new Button(getActivity());
                                confirm.setText("OK");
                                confirm.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if (otherText.length() > 0)
                                            radioOption.setText(otherText.getText());
                                        inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0);
                                        editOther.dismiss();
                                    }
                                });
                                editor.addView(confirm);
                            }
                        });
                    }
                }
                Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel);
                cancel_radio.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        current_dialog.cancel();
                    }
                });
                Button submit_radio = (Button) layout.findViewById(R.id.esm_submit);
                submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
                submit_radio.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (expires_seconds > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);

                        ContentValues rowData = new ContentValues();
                        rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());

                        RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio);
                        if (radioOptions.getCheckedRadioButtonId() != -1) {
                            RadioButton selected = (RadioButton) radioOptions
                                    .getChildAt(radioOptions.getCheckedRadioButtonId());
                            rowData.put(ESM_Data.ANSWER, selected.getText().toString());
                        }
                        rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                        sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                ESM_Data._ID + "=" + esm_id, null);

                        Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                        getActivity().sendBroadcast(answer);

                        if (Aware.DEBUG)
                            Log.d(TAG, "Answer:" + rowData.toString());

                        current_dialog.dismiss();
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case ESM.TYPE_ESM_CHECKBOX:
            try {
                final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes);
                final JSONArray checks = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES)));

                for (int i = 0; i < checks.length(); i++) {
                    final CheckBox checked = new CheckBox(getActivity());
                    checked.setText(checks.getString(i));
                    checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                if (buttonView.getText().equals("Other")) {
                                    checked.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            final Dialog editOther = new Dialog(getActivity());
                                            editOther.setTitle("Can you be more specific, please?");
                                            editOther.getWindow()
                                                    .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                            editOther.getWindow().setGravity(Gravity.TOP);
                                            editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT,
                                                    LayoutParams.WRAP_CONTENT);

                                            LinearLayout editor = new LinearLayout(getActivity());
                                            editor.setOrientation(LinearLayout.VERTICAL);
                                            editOther.setContentView(editor);
                                            editOther.show();

                                            final EditText otherText = new EditText(getActivity());
                                            editor.addView(otherText);

                                            Button confirm = new Button(getActivity());
                                            confirm.setText("OK");
                                            confirm.setOnClickListener(new View.OnClickListener() {
                                                @Override
                                                public void onClick(View v) {
                                                    if (otherText.length() > 0) {
                                                        inputManager.hideSoftInputFromWindow(
                                                                otherText.getWindowToken(), 0);
                                                        selected_options
                                                                .remove(buttonView.getText().toString());
                                                        checked.setText(otherText.getText());
                                                        selected_options.add(otherText.getText().toString());
                                                    }
                                                    editOther.dismiss();
                                                }
                                            });
                                            editor.addView(confirm);
                                        }
                                    });
                                } else {
                                    selected_options.add(buttonView.getText().toString());
                                }
                            } else {
                                selected_options.remove(buttonView.getText().toString());
                            }
                        }
                    });
                    checkboxes.addView(checked);
                }
                Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel);
                cancel_checkbox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        current_dialog.cancel();
                    }
                });
                Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit);
                submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
                submit_checkbox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (expires_seconds > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);

                        ContentValues rowData = new ContentValues();
                        rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());

                        if (selected_options.size() > 0) {
                            rowData.put(ESM_Data.ANSWER, selected_options.toString());
                        }

                        rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                        sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                ESM_Data._ID + "=" + esm_id, null);

                        Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                        getActivity().sendBroadcast(answer);

                        if (Aware.DEBUG)
                            Log.d(TAG, "Answer:" + rowData.toString());

                        current_dialog.dismiss();
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case ESM.TYPE_ESM_LIKERT:
            final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert);
            ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX)));
            ratingBar.setStepSize(
                    (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP)));
            ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX)));

            TextView min_label = (TextView) layout.findViewById(R.id.esm_min);
            min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL)));

            TextView max_label = (TextView) layout.findViewById(R.id.esm_max);
            max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL)));

            Button cancel = (Button) layout.findViewById(R.id.esm_cancel);
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    current_dialog.cancel();
                }
            });
            Button submit = (Button) layout.findViewById(R.id.esm_submit);
            submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (expires_seconds > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);

                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.ANSWER, ratingBar.getRating());
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                    sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                            ESM_Data._ID + "=" + esm_id, null);

                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    getActivity().sendBroadcast(answer);

                    if (Aware.DEBUG)
                        Log.d(TAG, "Answer:" + rowData.toString());

                    current_dialog.dismiss();
                }
            });
            break;
        case ESM.TYPE_ESM_QUICK_ANSWERS:
            try {
                final JSONArray answers = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS)));
                final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers);

                //If we have more than 3 possibilities, better that the UI is vertical for UX
                if (answers.length() > 3) {
                    answersHolder.setOrientation(LinearLayout.VERTICAL);
                }

                for (int i = 0; i < answers.length(); i++) {
                    final Button answer = new Button(getActivity());
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                            LayoutParams.WRAP_CONTENT, 1.0f);
                    answer.setLayoutParams(params);
                    answer.setText(answers.getString(i));
                    answer.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            if (expires_seconds > 0 && expire_monitor != null)
                                expire_monitor.cancel(true);

                            ContentValues rowData = new ContentValues();
                            rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                            rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                            rowData.put(ESM_Data.ANSWER, (String) answer.getText());

                            sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                    ESM_Data._ID + "=" + esm_id, null);

                            Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                            getActivity().sendBroadcast(answer);

                            if (Aware.DEBUG)
                                Log.d(TAG, "Answer:" + rowData.toString());

                            current_dialog.dismiss();
                        }
                    });
                    answersHolder.addView(answer);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        }
    }
    if (visible_esm != null && !visible_esm.isClosed())
        visible_esm.close();

    //Start dialog visibility threshold
    if (expires_seconds > 0) {
        expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id);
        expire_monitor.execute();
    }

    //Fixed: doesn't dismiss the dialog if touched outside or ghost touches
    current_dialog.setCanceledOnTouchOutside(false);

    return current_dialog;
}