Code example for RadioGroup

Methods: addViewgetChildCountgetCheckedRadioButtonId

0
				group.check(index);
				iconView.setImageResource(android.R.drawable.radiobutton_on_background);
 
			} 
		}); 
		if (group.getCheckedRadioButtonId() == index) {
			iconView.setImageResource(android.R.drawable.radiobutton_on_background);
		} else { 
			iconView.setImageResource(android.R.drawable.radiobutton_off_background);
		} 
		iconView.setBackgroundColor(Color.TRANSPARENT);
		buttonBox.addView(iconView, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.WRAP_CONTENT,
				LinearLayout.LayoutParams.WRAP_CONTENT, layoutWeightSelect));
		final EditText textInput = new EditText(context);
		textInput.setEnabled(true);
		textInput.setFocusable(true);
		if (item != null) {
			textInput.setText(item.getText());
		} else { 
			textInput.setText(" ");
			textInput.setText("");
		} 
		buttonBox.addView(textInput, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT, layoutWeightTextInput));
		ImageButton deleteButton = new ImageButton(context);
		deleteButton.setImageResource(android.R.drawable.ic_delete);
		deleteButton.setBackgroundColor(Color.TRANSPARENT);
		deleteButton.setOnClickListener(new OnClickListener() {
 
			@Override 
			public void onClick(View v) {
				if (textInput.getText().toString().equals("")) {
					group.removeViewAt(index);
					if (index < list.size()) {
						list.remove(index);
					} 
				} else { 
					if (!itemsToRemove.contains(index)) {
						textInput.setPaintFlags(textInput.getPaintFlags()
								| Paint.STRIKE_THRU_TEXT_FLAG);
						textInput.invalidate();
						itemsToRemove.add(index);
					} else { 
						itemsToRemove.remove((Integer) index);
						textInput.setPaintFlags(textInput.getPaintFlags()
								& (~Paint.STRIKE_THRU_TEXT_FLAG));
						textInput.invalidate();
					} 
				} 
 
			} 
		}); 
		buttonBox.addView(deleteButton, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.WRAP_CONTENT,
				LinearLayout.LayoutParams.WRAP_CONTENT, layoutWeightDelete));
 
		return buttonBox;
	} 
 
	@Override 
	public boolean save() { 
		for (int i = 0; i < group.getChildCount(); i++) {
			String itemText = ((TextView) ((LinearLayout) group.getChildAt(i))
					.getChildAt(1)).getText().toString();
			if (i <= list.size() - 1) {
				SelectableItem itemToSave = list.get(i);
				itemToSave.setText(itemText);
				itemToSave.setId(i);
			} else { 
				addNewItemToSelectableList(i, itemText);
			} 
 
		} 
 
		selectedItem = group.getCheckedRadioButtonId();
		Collections.sort(itemsToRemove);
		for (int i = itemsToRemove.size() - 1; i >= 0; i--) {
			if (itemsToRemove.get(i) == selectedItem) {
				((LinearLayout) group.getChildAt(itemsToRemove.get(i)))
						.requestFocus();
				return false; 
			} 
			removeItem(itemsToRemove.get(i));
			if (selectedItem > itemsToRemove.get(i)) {
				selectedItem--;
			} 
		} 
 
		setSelectedItemId(selectedItem);
 
		return true; 
 
	} 
 
	public void addNewEmptyItem(Context context) {
		LinearLayout emptyItem = createOptionRow(context,
				group.getChildCount(), null);
		group.addView(emptyItem, new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT));
		emptyItem.requestFocus();
	}