addView ( )源码实例Demo

android.widget.RadioGroup#addView ( )源码实例Demo

下面列出了android.widget.RadioGroup#addView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LaunchTime   文件: BackupActivity.java
private RadioButton makeRadioButton(RadioGroup baks, final String bk, final boolean item) {
    RadioButton bkb = new RadioButton(this);
    bkb.setText(bk);


    bkb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                selectedBackup = bk;
                selected = item;
                Log.d("backuppage", "selected = " + selectedBackup);
                backupSelected(selected);
            }
        }
    });

    baks.addView(bkb);
    return bkb;
}
 
@Test
public void baseRadioGroupOnCheckChangeEmitOnlyCheckEvent() throws InterruptedException {
    Context appContext = InstrumentationRegistry.getTargetContext();
    RadioGroup radioGroup = new RadioGroup(appContext);
    CountingOnCheckedChangeListener listener = new CountingOnCheckedChangeListener();
    radioGroup.setOnCheckedChangeListener(listener);

    final RadioButton firstButton = new RadioButton(appContext);
    firstButton.setText("first");
    firstButton.setId(R.id.multi_line_radio_group_default_radio_button);
    radioGroup.addView(firstButton);
    final RadioButton secondButton = new RadioButton(appContext);
    secondButton.setText("second");
    secondButton.setId(R.id.multi_line_radio_group_default_table_row);
    radioGroup.addView(secondButton);

    clickButton(secondButton);
    clickButton(firstButton);

    assertEquals(2, listener.count);
    assertEquals(Arrays.asList(true, true), listener.buttonState);
    assertEquals(Arrays.asList("second", "first"), listener.buttonText);
}
 
源代码3 项目: Car-Pooling   文件: SearchActivity.java
/**
 * This method is used to display all the rides available to specific destination
 * @param rideInfos all the rides that are available
 */
private void addRadioButton(RideInfo[] rideInfos) {

    RadioGroup radioGroup= (RadioGroup) findViewById(R.id.RadioButtonGroup);
    RadioGroup.LayoutParams rprms;
    radioGroup.removeAllViews();

    if(rideInfos.length>0)
    {
        for(int i=0;i<(rideInfos.length);i++){
            RadioButton radioButton = new RadioButton(this);
            radioButton.setText("CAR NO- " + rideInfos[i].getCar_Num() + " -Source- " + rideInfos[i].getSource() + " -Destination- " + rideInfos[i].getDestination() + " -Time- " + rideInfos[i].getRideTime());
            radioButton.setId(i);
            rprms= new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
            radioGroup.addView(radioButton, rprms);
        }
    }
    else
    {
        Toast.makeText(SearchActivity.this, "No Rides available to destination.. Please try again", Toast.LENGTH_SHORT).show();
    }
}
 
源代码4 项目: prayer-times-android   文件: LanguageFragment.java
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.intro_language, container, false);
    RadioGroup radioGroup = v.findViewById(R.id.radioGroup);
    
    List<LocaleUtils.Translation> langs = LocaleUtils.getSupportedLanguages(getActivity());
    String currentLang = Preferences.LANGUAGE.get();
    int pos = 0;
    for (int i = 0; i < langs.size(); i++) {
        LocaleUtils.Translation lang = langs.get(i);
        if (lang.getLanguage().equals(currentLang))
            pos = i + 1;
        RadioButton button = new RadioButton(getContext());
        button.setTag(lang.getLanguage());
        button.setText(lang.getDisplayText());
        button.setTextColor(getResources().getColor(R.color.white));
        button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        int padding = (int) (button.getTextSize() / 2);
        button.setPadding(padding, padding, padding, padding);
        button.setOnCheckedChangeListener(this);
        radioGroup.addView(button);
    }
    if (pos != 0)
        ((RadioButton) radioGroup.getChildAt(pos)).setChecked(true);
    return v;
}
 
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Toolbar toolbar = view.findViewById(R.id.toolbar);
    ((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);

    List<String> androidVersions = new ArrayList<>(Arrays.asList(getResources().getStringArray(
            R.array.android_versions)));
    final int correctAnswerIndex = androidVersions.indexOf(getString(R.string.lollipop));
    final RadioGroup radioGroup = view.findViewById(R.id.radio_group);
    mFeedbackTextView = view.findViewById(R.id.feedback_text_view);

    if (radioGroup != null && correctAnswerIndex != -1) {
        for (int i = 0; i < androidVersions.size(); i++) {
            RadioButton radioButton = new RadioButton(getContext());
            radioButton.setText(androidVersions.get(i));
            radioButton.setId(i);
            radioButton.setPadding(36, 36, 36, 36 );
            radioButton.setTextSize(18f);
            radioGroup.addView(radioButton);
        }

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int indexOfCheckedChild = radioGroup.indexOfChild(view.findViewById(checkedId));
                if (indexOfCheckedChild == correctAnswerIndex) {
                    mFeedbackTextView.setText(R.string.correct);
                    mFeedbackTextView.setBackgroundColor(ContextCompat.getColor(requireContext(),
                            R.color.green));
                } else {
                    mFeedbackTextView.setText(R.string.incorrect);
                    mFeedbackTextView.setBackgroundColor(ContextCompat.getColor(requireContext(),
                            R.color.red));
                }
            }
        });
    }
}
 
@NonNull
private AppCompatRadioButton createCompatRadioButton(
    RadioGroup group, String contentDescription) {
  AppCompatRadioButton button = new AppCompatRadioButton(getContext());
  button.setContentDescription(contentDescription);
  group.addView(button);
  return button;
}
 
@Override
public void createViews(Context context, ViewGroup layout) {
    RadioGroup group = new RadioGroup(context);

    TextView tv = new TextView(context);
    PixateFreestyle.setStyleId(tv, "rgTitle");
    tv.setText("Will you be attending?");
    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    group.addView(tv);

    String[] titles = new String[] { "Yes", "No", "Maybe" };

    Integer id = null;
    for (String title : titles) {
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        RadioButton rb = new RadioButton(context);

        PixateFreestyle.setStyleClass(rb, "myRadioButton");
        PixateFreestyle.setStyleId(rb, "myRadioButton" + title);
        rb.setText(title);
        group.addView(rb, params);

        if (id == null) {
            id = rb.getId();
        }
    }

    layout.addView(group,
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    group.check(id);
    addView(group);
}
 
源代码8 项目: fab   文件: FABActivity.java
private void populateAnimationsRadioGroup(RadioGroup group, Set<RadioButtons.AnimationInfo> animationInfos) {
	for (RadioButtons.AnimationInfo animationInfo : animationInfos) {
		final RadioButton button = new RadioButton(this);
		final String text = getResources().getString(animationInfo.animationTextResId);
		button.setId(IdGenerator.next());
		button.setText(text);
		button.setTag(animationInfo);
		button.setEnabled(buttonBehaviorRadioGroup.getCheckedRadioButtonId() ==
				R.id.fab_activity_radiobutton_hide_and_show_on_click_radiobutton);
		group.addView(button);
	}
}
 
@Test
public void baseRadioGroupOnCheckChangeEmitsOnClearCheck() throws InterruptedException {
    Context appContext = InstrumentationRegistry.getTargetContext();
    final RadioGroup radioGroup = new RadioGroup(appContext);
    CountingOnCheckedChangeListener listener = new CountingOnCheckedChangeListener();
    radioGroup.setOnCheckedChangeListener(listener);

    final RadioButton firstButton = new RadioButton(appContext);
    firstButton.setText("first");
    firstButton.setId(R.id.multi_line_radio_group_default_radio_button);
    radioGroup.addView(firstButton);
    assertEquals(0, listener.count);

    clickButton(firstButton);
    assertEquals(1, listener.count);

    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            radioGroup.clearCheck();
        }
    });

    assertEquals(Arrays.asList(true, false), listener.buttonState);
    assertEquals(Arrays.asList("first", "first", null), listener.buttonText);
    assertEquals(3, listener.count);
}
 
@SuppressLint("SetTextI18n")
private void clickAgainDoesNotEmitEvent(Context appContext, RadioGroup radioGroup) throws InterruptedException {
    final RadioButton firstButton = new RadioButton(appContext);
    firstButton.setText("first");
    firstButton.setId(R.id.multi_line_radio_group_default_radio_button);
    radioGroup.addView(firstButton);
    final RadioButton secondButton = new RadioButton(appContext);
    secondButton.setText("second");
    secondButton.setId(R.id.multi_line_radio_group_default_table_row);
    radioGroup.addView(secondButton);

    clickButton(secondButton);
    clickButton(secondButton);
}
 
源代码11 项目: PocketMaps   文件: Dialog.java
public static void showUnitTypeSelector(Activity activity)
{
  AlertDialog.Builder builder1 = new AlertDialog.Builder(activity);
  builder1.setTitle(R.string.units);
  builder1.setCancelable(true);
  
  final RadioButton rb1 = new RadioButton(activity.getBaseContext());
  rb1.setText(R.string.units_metric);

  final RadioButton rb2 = new RadioButton(activity.getBaseContext());
  rb2.setText(R.string.units_imperal);
  
  final RadioGroup rg = new RadioGroup(activity.getBaseContext());
  rg.addView(rb1);
  rg.addView(rb2);
  rg.check(Variable.getVariable().isImperalUnit() ? rb2.getId() : rb1.getId());
  
  builder1.setView(rg);
  OnClickListener listener = new OnClickListener()
  {
    @Override
    public void onClick(DialogInterface dialog, int buttonNr)
    {
      Variable.getVariable().setImperalUnit(rb2.isChecked());
      Variable.getVariable().saveVariables(Variable.VarType.Base);
    }
  };
  builder1.setPositiveButton(R.string.ok, listener);
  AlertDialog alert11 = builder1.create();
  alert11.show();
}
 
源代码12 项目: ResearchStack   文件: MultiChoiceQuestionBody.java
private View initViewDefault(LayoutInflater inflater, ViewGroup parent) {
    RadioGroup radioGroup = new RadioGroup(inflater.getContext());
    radioGroup.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    radioGroup.setDividerDrawable(ContextCompat.getDrawable(parent.getContext(),
            R.drawable.rsb_divider_empty_8dp));

    for (int i = 0; i < choices.length; i++) {
        Choice<T> item = choices[i];

        // Create & add the View to our body-view
        AppCompatCheckBox checkBox = (AppCompatCheckBox) inflater.inflate(R.layout.rsb_item_checkbox,
                radioGroup,
                false);
        checkBox.setText(item.getText());
        checkBox.setId(i);
        radioGroup.addView(checkBox);

        // Set initial state
        if (currentSelected.contains(item.getValue())) {
            checkBox.setChecked(true);
        }

        // Update result when value changes
        checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {

            if (isChecked) {
                currentSelected.add(item.getValue());
            } else {
                currentSelected.remove(item.getValue());
            }
        });
    }

    return radioGroup;
}
 
源代码13 项目: prayer-times-android   文件: LanguageFragment.java
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.intro_language, container, false);
    RadioGroup radioGroup = v.findViewById(R.id.radioGroup);
    
    List<LocaleUtils.Translation> langs = LocaleUtils.getSupportedLanguages(getActivity());
    String currentLang = Preferences.LANGUAGE.get();
    int pos = 0;
    for (int i = 0; i < langs.size(); i++) {
        LocaleUtils.Translation lang = langs.get(i);
        if (lang.getLanguage().equals(currentLang))
            pos = i + 1;
        RadioButton button = new RadioButton(getContext());
        button.setTag(lang.getLanguage());
        button.setText(lang.getDisplayText());
        button.setTextColor(getResources().getColor(R.color.white));
        button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        int padding = (int) (button.getTextSize() / 2);
        button.setPadding(padding, padding, padding, padding);
        button.setOnCheckedChangeListener(this);
        radioGroup.addView(button);
    }
    if (pos != 0)
        ((RadioButton) radioGroup.getChildAt(pos)).setChecked(true);
    return v;
}
 
源代码14 项目: Twire   文件: LayoutSelector.java
private void init() {
    layoutSelectorView = activity.getLayoutInflater().inflate(R.layout.stream_layout_preview, null);
    final RadioGroup rg = layoutSelectorView.findViewById(R.id.layouts_radiogroup);
    final FrameLayout previewWrapper = layoutSelectorView.findViewById(R.id.preview_wrapper);

    if (previewMaxHeightRes != -1) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                (int) activity.getResources().getDimension(previewMaxHeightRes)
        );
        previewWrapper.setLayoutParams(lp);
        //previewWrapper.setMinimumHeight((int) activity.getResources().getDimension(previewMaxHeightRes));
    }

    ViewStub preview = layoutSelectorView.findViewById(R.id.layout_stub);
    preview.setLayoutResource(previewLayout);
    final View inflated = preview.inflate();

    for (int i = 0; i < layoutTitles.length; i++) {
        final String layoutTitle = layoutTitles[i];

        final AppCompatRadioButton radioButton = new AppCompatRadioButton(activity);
        radioButton.setText(layoutTitle);

        final int finalI = i;
        radioButton.setOnClickListener(v -> selectCallback.onSelected(layoutTitle, finalI, inflated));

        if (textColor != -1) {
            radioButton.setTextColor(Service.getColorAttribute(textColor, R.color.black_text, activity));

            ColorStateList colorStateList = new ColorStateList(
                    new int[][]{
                            new int[]{-android.R.attr.state_checked},
                            new int[]{android.R.attr.state_checked}
                    },
                    new int[]{

                            Color.GRAY, //Disabled
                            Service.getColorAttribute(R.attr.colorAccent, R.color.accent, activity), //Enabled
                    }
            );
            radioButton.setSupportButtonTintList(colorStateList);
        }


        radioButton.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, // Width
                (int) activity.getResources().getDimension(R.dimen.layout_selector_height) // Height
        ));


        rg.addView(radioButton, i);


        if ((selectedLayoutIndex != -1 && selectedLayoutIndex == i) || (selectedLayoutTitle != null && selectedLayoutTitle.equals(layoutTitle))) {
            radioButton.performClick();
        }
    }
}
 
源代码15 项目: ClassSchedule   文件: SettingFragment.java
private void showThemeDialog() {
    ScrollView scrollView = new ScrollView(getActivity());
    RadioGroup radioGroup = new RadioGroup(getActivity());
    scrollView.addView(radioGroup);
    int margin = ScreenUtils.dp2px(16);
    radioGroup.setPadding(margin / 2, margin, margin, margin);

    for (int i = 0; i < themeColorArray.length; i++) {
        AppCompatRadioButton arb = new AppCompatRadioButton(getActivity());

        RadioGroup.LayoutParams params =
                new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

        arb.setLayoutParams(params);
        arb.setId(i);
        arb.setTextColor(getResources().getColor(themeColorArray[i]));
        arb.setText(themeNameArray[i]);
        arb.setTextSize(16);
        arb.setPadding(0, margin / 2, 0, margin / 2);
        radioGroup.addView(arb);
    }

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            theme = checkedId;
        }
    });

    DialogHelper dialogHelper = new DialogHelper();
    dialogHelper.showCustomDialog(getActivity(), scrollView,
            getString(R.string.theme_preference), new DialogListener() {
                @Override
                public void onPositive(DialogInterface dialog, int which) {
                    super.onPositive(dialog, which);
                    dialog.dismiss();
                    String key = getString(R.string.app_preference_theme);
                    int oldTheme = Preferences.getInt(key, 0);

                    if (theme != oldTheme) {
                        Preferences.putInt(key, theme);
                        ActivityUtil.finishAll();
                        startActivity(new Intent(app.mContext, CourseActivity.class));
                    }
                }
            });
}
 
源代码16 项目: Pocket-Plays-for-Twitch   文件: LayoutSelector.java
private void init() {
	layoutSelectorView = activity.getLayoutInflater().inflate(R.layout.stream_layout_preview, null);
	final RadioGroup rg = (RadioGroup) layoutSelectorView.findViewById(R.id.layouts_radiogroup);
	final FrameLayout previewWrapper = (FrameLayout) layoutSelectorView.findViewById(R.id.preview_wrapper);

	if (previewMaxHeightRes != -1) {
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				(int) activity.getResources().getDimension(previewMaxHeightRes)
		);
		previewWrapper.setLayoutParams(lp);
		//previewWrapper.setMinimumHeight((int) activity.getResources().getDimension(previewMaxHeightRes));
	}

	ViewStub preview = (ViewStub) layoutSelectorView.findViewById(R.id.layout_stub);
	preview.setLayoutResource(previewLayout);
	final View inflated = preview.inflate();

	for (int i = 0; i < layoutTitles.length; i++) {
		final String layoutTitle = layoutTitles[i];

		final AppCompatRadioButton radioButton = new AppCompatRadioButton(activity);
		radioButton.setText(layoutTitle);

		final int finalI = i;
		radioButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				selectCallback.onSelected(layoutTitle, finalI, inflated);
			}
		});

		if (textColor != -1) {
			radioButton.setTextColor(Service.getColorAttribute(textColor, R.color.black_text, activity));

			ColorStateList colorStateList = new ColorStateList(
					new int[][]{
							new int[]{-android.R.attr.state_checked},
							new int[]{android.R.attr.state_checked}
					},
					new int[]{

							Color.GRAY, //Disabled
							Service.getColorAttribute(R.attr.colorAccent, R.color.accent, activity), //Enabled
					}
			);
			radioButton.setSupportButtonTintList(colorStateList);
		}


		radioButton.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT, // Width
				(int) activity.getResources().getDimension(R.dimen.layout_selector_height) // Height
		));


		rg.addView(radioButton, i);


		if ((selectedLayoutIndex != -1 && selectedLayoutIndex == i) || (selectedLayoutTitle != null && selectedLayoutTitle.equals(layoutTitle))) {
			radioButton.performClick();
		}
	}
}
 
源代码17 项目: Status   文件: FontPreferenceData.java
@Override
public void onClick(View v) {
    ScrollView scrollView = new ScrollView(getContext());

    RadioGroup group = new RadioGroup(getContext());
    int vPadding = DimenUtils.dpToPx(12);
    group.setPadding(0, vPadding, 0, vPadding);

    AppCompatRadioButton normalButton = (AppCompatRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.item_dialog_radio_button, group, false);
    normalButton.setId(0);
    normalButton.setText(R.string.font_default);
    normalButton.setChecked(preference == null || preference.length() == 0);
    group.addView(normalButton);

    for (int i = 0; i < items.size(); i++) {
        String item = items.get(i);

        AppCompatRadioButton button = (AppCompatRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.item_dialog_radio_button, group, false);
        button.setId(i + 1);
        button.setText(item.replace(".ttf", ""));
        button.setTag(item);
        try {
            button.setTypeface(Typeface.createFromAsset(getContext().getAssets(), item));
        } catch (Exception e) {
            continue;
        }
        button.setChecked(preference != null && preference.equals(item));
        group.addView(button);
    }

    group.setOnCheckedChangeListener((group1, checkedId) -> {
        for (int i = 0; i < group1.getChildCount(); i++) {
            RadioButton child = (RadioButton) group1.getChildAt(i);
            child.setChecked(child.getId() == checkedId);
            if (child.getId() == checkedId)
                selectedPreference = (String) child.getTag();
        }
    });

    scrollView.addView(group);

    new AlertDialog.Builder(getContext())
            .setTitle(getIdentifier().getTitle())
            .setView(scrollView)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                FontPreferenceData.this.preference = selectedPreference;

                getIdentifier().setPreferenceValue(getContext(), selectedPreference);
                onPreferenceChange(selectedPreference);
                selectedPreference = null;
            })
            .setNegativeButton(android.R.string.cancel, (dialog, which) -> selectedPreference = null)
            .show();
}
 
源代码18 项目: SuperToasts   文件: AttributeRadioGroupFragment.java
@Nullable
@Override
@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;
}
 
源代码19 项目: PdDroidPublisher   文件: MidiOutputCreateDialog.java
@Override
protected void onCreate(Bundle savedInstanceState) 
{
	super.onCreate(savedInstanceState);
	
	setTitle("IP MIDI Output creation");

	LinearLayout view = new LinearLayout(getContext());
	view.setOrientation(LinearLayout.VERTICAL);
	
	RadioGroup rg = new RadioGroup(getContext());
	
	final RadioButton rbMulticast = new RadioButton(getContext());
	rbMulticast.setText("RAW/Multicast");
	
	final RadioButton rbUnicast = new RadioButton(getContext());
	rbUnicast.setText("RAW/Unicast");
	
	rg.addView(rbUnicast);
	rg.addView(rbMulticast);
	
	rbUnicast.setChecked(true);
	
	final EditText tvIP = new EditText(getContext());
	tvIP.setText("127.0.0.1");
	
	final EditText tvPORT = new EditText(getContext());
	tvPORT.setInputType(InputType.TYPE_CLASS_NUMBER);
	tvPORT.setText("21929");
	
	Button btOk = new Button(getContext());
	btOk.setText("Create");
	
	btOk.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) 
		{
			IPMidiOutput output = new IPMidiOutput();
			output.multicast = rbMulticast.isChecked();
			output.ip = tvIP.getText().toString();
			output.port = Integer.parseInt(tvPORT.getText().toString());
			device.outputs.add(output);
			MidiOutputCreateDialog.this.dismiss();
		}
	});
	
	view.addView(rg);
	view.addView(tvIP);
	view.addView(tvPORT);
	view.addView(btOk);
	
	setContentView(view);
}
 
源代码20 项目: Dashchan   文件: ReencodingDialog.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
	Context context = getActivity();
	qualityForm = new SeekBarForm(false);
	qualityForm.setConfiguration(1, 100, 1, 1);
	qualityForm.setValueFormat(getString(R.string.text_quality_format));
	qualityForm.setCurrentValue(savedInstanceState != null ? savedInstanceState.getInt(EXTRA_QUALITY) : 100);
	reduceForm = new SeekBarForm(false);
	reduceForm.setConfiguration(1, 8, 1, 1);
	reduceForm.setValueFormat(getString(R.string.text_reduce_format));
	reduceForm.setCurrentValue(savedInstanceState != null ? savedInstanceState.getInt(EXTRA_REDUCE) : 1);
	int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
	View qualityView = qualityForm.inflate(context);
	qualityForm.getSeekBar().setSaveEnabled(false);
	qualityView.setPadding(qualityView.getPaddingLeft(), 0, qualityView.getPaddingRight(), padding / 2);
	View reduceView = reduceForm.inflate(context);
	reduceForm.getSeekBar().setSaveEnabled(false);
	reduceView.setPadding(reduceView.getPaddingLeft(), 0, reduceView.getPaddingRight(),
			reduceView.getPaddingBottom());
	radioGroup = new RadioGroup(context);
	radioGroup.setOrientation(RadioGroup.VERTICAL);
	radioGroup.setPadding(padding, padding, padding, padding / 2);
	radioGroup.setOnCheckedChangeListener(this);
	for (int i = 0; i < OPTIONS.length; i++) {
		RadioButton radioButton = new RadioButton(context);
		radioButton.setText(OPTIONS[i]);
		radioButton.setId(IDS[i]);
		radioGroup.addView(radioButton);
	}
	radioGroup.check(IDS[0]);
	LinearLayout linearLayout = new LinearLayout(context);
	linearLayout.setOrientation(LinearLayout.VERTICAL);
	FrameLayout qualityLayout = new FrameLayout(context);
	qualityLayout.setId(android.R.id.text1);
	qualityLayout.addView(qualityView);
	FrameLayout reduceLayout = new FrameLayout(context);
	reduceLayout.setId(android.R.id.text2);
	reduceLayout.addView(reduceView);
	linearLayout.addView(radioGroup, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	linearLayout.addView(qualityLayout, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	linearLayout.addView(reduceLayout, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	ScrollView scrollView = new ScrollView(context);
	scrollView.addView(linearLayout, ScrollView.LayoutParams.MATCH_PARENT,
			ScrollView.LayoutParams.WRAP_CONTENT);
	return new AlertDialog.Builder(context).setTitle(R.string.text_reencode_image)
			.setView(scrollView).setNegativeButton(android.R.string.cancel, null)
			.setPositiveButton(android.R.string.ok, this).create();
}