use of android.widget.RadioGroup in project AndroidDevelop by 7449.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewpager);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rg_group);
imageView = (ImageView) findViewById(R.id.iv_line);
Display display = getWindow().getWindowManager().getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
ivWidth = (dm.widthPixels / 3);
viewPager.addOnPageChangeListener(this);
radioGroup.setOnCheckedChangeListener(this);
viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return ViewPagerFragment.startFragment(position);
}
@Override
public int getCount() {
return 3;
}
});
}
use of android.widget.RadioGroup in project JustAndroid by chinaltz.
the class SegmentedGroup method updateBackground.
private void updateBackground(View view) {
if (!isInEditMode()) {
int checked = mLayoutSelector.getSelected();
int unchecked = mLayoutSelector.getUnselected();
//Set text color
ColorStateList colorStateList = new ColorStateList(new int[][] { { -android.R.attr.state_checked }, { android.R.attr.state_checked } }, new int[] { mTintColor, mCheckedTextColor });
((Button) view).setTextColor(colorStateList);
//Redraw with tint color
Drawable checkedDrawable = resources.getDrawable(checked).mutate();
Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
((GradientDrawable) checkedDrawable).setColor(mTintColor);
((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor);
((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor);
((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor);
//Set proper radius
((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
GradientDrawable maskDrawable = (GradientDrawable) resources.getDrawable(unchecked).mutate();
maskDrawable.setStroke(mMarginDp, mTintColor);
maskDrawable.setColor(mUnCheckedTintColor);
maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view));
int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
maskDrawable.setColor(maskColor);
LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] { uncheckedDrawable, maskDrawable });
Drawable[] drawables = { uncheckedDrawable, checkedDrawable };
TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
if (((RadioButton) view).isChecked()) {
transitionDrawable.reverseTransition(0);
}
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_pressed }, pressedDrawable);
stateListDrawable.addState(StateSet.WILD_CARD, transitionDrawable);
mDrawableMap.put(view.getId(), transitionDrawable);
//Set button background
if (Build.VERSION.SDK_INT >= 16) {
view.setBackground(stateListDrawable);
} else {
view.setBackgroundDrawable(stateListDrawable);
}
super.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
TransitionDrawable current = mDrawableMap.get(checkedId);
current.reverseTransition(200);
if (mLastCheckId != 0) {
TransitionDrawable last = mDrawableMap.get(mLastCheckId);
if (last != null)
last.reverseTransition(200);
}
mLastCheckId = checkedId;
if (mCheckedChangeListener != null) {
mCheckedChangeListener.onCheckedChanged(group, checkedId);
}
}
});
}
}
use of android.widget.RadioGroup in project ngAndroid by davityle.
the class NgChange method attach.
@Override
public void attach(Scope scope, View view, int layoutId, int viewId, Tuple<String, String>[] models) {
Executor executor = new Executor(scope, layoutId, viewId, getAttribute());
if (view instanceof CompoundButton) {
CompoundButton button = (CompoundButton) view;
button.setOnCheckedChangeListener(executor);
} else if (view instanceof TextView) {
TextView textView = (TextView) view;
textView.addTextChangedListener(executor);
} else if (view instanceof Spinner) {
Spinner spinner = (Spinner) view;
spinner.setOnItemSelectedListener(executor);
} else if (view instanceof RadioGroup) {
RadioGroup group = (RadioGroup) view;
group.setOnCheckedChangeListener(executor);
}
}
use of android.widget.RadioGroup in project android_frameworks_base by crdroidandroid.
the class NotificationBuilderTest method getRadioTag.
private String getRadioTag(int id) {
final RadioGroup g = (RadioGroup) findViewById(id);
final View v = findViewById(g.getCheckedRadioButtonId());
return (String) v.getTag();
}
use of android.widget.RadioGroup in project LiveLessons by douglascraigschmidt.
the class AndroidPlatform method buttonToggled.
/**
* Retrieves textual input of the toggled button determined by the
* user.
*/
private String buttonToggled() {
Log.e("AndroidPlatform", "buttonToggled");
/** Checks the format radio group for checked buttons. */
RadioGroup rg = (RadioGroup) activity.findViewById(R.id.rad1);
for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
return ("format" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
/** Checks the print radio group for checked buttons. */
rg = (RadioGroup) activity.findViewById(R.id.rad2);
for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled()) {
((TextView) activity.findViewById(R.id.tv)).setText("");
return ("print" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
}
/** Checks the eval radio group for checked buttons. */
rg = (RadioGroup) activity.findViewById(R.id.rad3);
for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
return ("eval" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
/** Checks the set checkbox. */
CheckBox cb = (CheckBox) activity.findViewById(R.id.cb);
if (cb.isChecked() && cb.isEnabled())
return ("set" + (String) ((TextView) cb).getText()).toLowerCase();
return "expr";
}
Aggregations