public SelectOneAutoAdvanceWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); LayoutInflater inflater = LayoutInflater.from(getContext()); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } buttons = new ArrayList<RadioButton>(); listener = (AdvanceToNextListener) context; String s = null; if (prompt.getAnswerValue() != null) { s = ((Selection) prompt.getAnswerValue().getValue()).getValue(); } // use this for recycle Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.expander_ic_right); if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { RelativeLayout thisParentLayout = (RelativeLayout) inflater.inflate(R.layout.quick_select_layout, null); LinearLayout questionLayout = (LinearLayout) thisParentLayout.getChildAt(0); ImageView rightArrow = (ImageView) thisParentLayout.getChildAt(1); RadioButton r = new RadioButton(getContext()); r.setText(prompt.getSelectChoiceText(mItems.get(i))); r.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); r.setTag(Integer.valueOf(i)); r.setId(QuestionWidget.newUniqueId()); r.setEnabled(!prompt.isReadOnly()); r.setFocusable(!prompt.isReadOnly()); rightArrow.setImageBitmap(b); buttons.add(r); if (mItems.get(i).getValue().equals(s)) { r.setChecked(true); } r.setOnCheckedChangeListener(this); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText( mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT(prompt.getIndex(), "", r, audioURI, imageURI, videoURI, bigImageURI); if (i != mItems.size() - 1) { // Last, add the dividing line (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); mediaLayout.addDivider(divider); } questionLayout.addView(mediaLayout); addView(thisParentLayout); } } }
public SelectOneWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } buttons = new ArrayList<RadioButton>(); // Layout holds the vertical list of buttons LinearLayout buttonLayout = new LinearLayout(context); String s = null; if (prompt.getAnswerValue() != null) { s = ((Selection) prompt.getAnswerValue().getValue()).getValue(); } if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { RadioButton r = new RadioButton(getContext()); r.setText(prompt.getSelectChoiceText(mItems.get(i))); r.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); r.setTag(Integer.valueOf(i)); r.setId(QuestionWidget.newUniqueId()); r.setEnabled(!prompt.isReadOnly()); r.setFocusable(!prompt.isReadOnly()); buttons.add(r); if (mItems.get(i).getValue().equals(s)) { r.setChecked(true); } r.setOnCheckedChangeListener(this); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText( mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT( prompt.getIndex(), "." + Integer.toString(i), r, audioURI, imageURI, videoURI, bigImageURI); if (i != mItems.size() - 1) { // Last, add the dividing line (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); mediaLayout.addDivider(divider); } buttonLayout.addView(mediaLayout); } } buttonLayout.setOrientation(LinearLayout.VERTICAL); // The buttons take up the right half of the screen LayoutParams buttonParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); addView(buttonLayout, buttonParams); }