List of usage examples for android.widget RadioButton RadioButton
public RadioButton(Context context)
From source file:org.telegram.ui.Cells.RadioButtonCell.java
public RadioButtonCell(Context context) { super(context); setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); setElevation(AndroidUtilities.dp(2)); if (paint == null) { paint = new Paint(); paint.setColor(ContextCompat.getColor(context, R.color.divider)); paint.setStrokeWidth(1);// www .j a v a2 s . co m } radioButton = new RadioButton(context); radioButton.setClickable(false); radioButton.setFocusable(false); radioButton.setBackground(null); radioButton.setScaleX(22f / 24); radioButton.setScaleY(22f / 24); //radioButton.setSize(AndroidUtilities.dp(20)); //radioButton.setColor(0xffb3b3b3, 0xff37a9f0); addView(radioButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 0 : 12), 6, (LocaleController.isRTL ? 12 : 0), 0)); textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setLines(1); textView.setMaxLines(1); textView.setSingleLine(true); textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 17 : 51), 10, (LocaleController.isRTL ? 51 : 17), 0)); valueTextView = new TextView(context); //valueTextView.setTextColor(0xff8a8a8a); valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); valueTextView.setLines(0); valueTextView.setMaxLines(0); valueTextView.setSingleLine(false); valueTextView.setPadding(0, 0, 0, AndroidUtilities.dp(12)); addView(valueTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 17 : 51), 35, (LocaleController.isRTL ? 51 : 17), 0)); }
From source file:org.telegram.ui.Cells.RadioCell.java
public RadioCell(Context context) { super(context); if (paint == null) { paint = new Paint(); paint.setColor(ContextCompat.getColor(context, R.color.divider)); paint.setStrokeWidth(1);/*from www . j a v a2s . c o m*/ } setElevation(AndroidUtilities.dp(2)); setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setLines(1); textView.setMaxLines(1); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 0, 17, 0)); radioButton = new RadioButton(context); radioButton.setClickable(false); radioButton.setFocusable(false); radioButton.setBackground(null); /*radioButton.setSize(AndroidUtilities.dp(20)); radioButton.setColor(0xffb3b3b3, 0xff37a9f0);*/ addView(radioButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, (LocaleController.isRTL ? 18 : 0), 0, (LocaleController.isRTL ? 0 : 18), 0)); }
From source file:com.mifos.mifosxdroid.online.SurveyQuestionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_survey_question, container, false); ButterKnife.inject(this, view); thiscontext = container.getContext(); mQuestionDatas = (new Gson()).fromJson(getArguments().getString(QUESTION_DATA), QuestionDatas.class); mScorecardValues = new ScorecardValues(); tv_question.setText(mQuestionDatas.getText()); ViewGroup hourButtonLayout = (ViewGroup) view.findViewById(R.id.radio1); for (int i = 0; i < mQuestionDatas.getResponseDatas().size(); i++) { button1 = new RadioButton(thiscontext); button1.setId(i);/*from w w w.j a v a 2 s . co m*/ button1.setText(mQuestionDatas.getResponseDatas().get(i).getText()); hourButtonLayout.addView(button1); radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup mRadioGroup2, int checkedId2) { for (int j = 0; j < mRadioGroup2.getChildCount(); j++) { btn = (RadioButton) mRadioGroup2.getChildAt(j); int t = mRadioGroup2.getId(); Log.d(LOG_TAG, "" + t); if (btn.getId() == checkedId2) { answer = btn.getText().toString(); mScorecardValues.setQuestionId(mQuestionDatas.getQuestionId()); mScorecardValues .setResponseId(mQuestionDatas.getResponseDatas().get(j).getResponseId()); mScorecardValues.setValue(mQuestionDatas.getResponseDatas().get(j).getValue()); mCallback.answer(mScorecardValues); Log.d(LOG_TAG, "Q R V" + mQuestionDatas.getQuestionId() + " " + mQuestionDatas.getResponseDatas().get(j).getResponseId() + " " + mQuestionDatas.getResponseDatas().get(j).getValue()); return; } } } }); } return view; }
From source file:edu.csh.coursebrowser.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); this.setTitle("Settings"); final SharedPreferences sp = SchoolActivity.sp; LinearLayout ll = (LinearLayout) this.findViewById(R.id.settings_layout); ll.setGravity(Gravity.CENTER);/*from w ww . j a v a2 s. c o m*/ final TextView tv = new TextView(this); if (!sp.contains("quarter")) { SharedPreferences.Editor e = sp.edit(); e.putString("quarter", "20122"); e.commit(); } tv.setText("Current Quarter: " + sp.getString("quarter", "20122")); Button b = new Button(this); b.setText("Change Quarter"); ll.addView(tv); ll.addView(b); ll.setPadding(10, 10, 10, 10); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { AlertDialog.Builder changeQuarter = new AlertDialog.Builder(SettingsActivity.this); changeQuarter.setTitle("Change Quarter"); changeQuarter.setMessage("Select New Quarter"); final RadioButton ld = new RadioButton(SettingsActivity.this); ld.setText("20121"); ld.setId(1); final RadioButton s = new RadioButton(SettingsActivity.this); s.setText("20122 (Current)"); s.setId(2); final RadioButton d = new RadioButton(SettingsActivity.this); d.setText("20123"); d.setId(3); final RadioGroup rg = new RadioGroup(SettingsActivity.this); rg.addView(ld); rg.addView(s); rg.addView(d); changeQuarter.setView(rg); changeQuarter.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); changeQuarter.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String q; int n = rg.getCheckedRadioButtonId(); if (n == 1) q = "20121"; else if (n == 2) q = "20122"; else q = "20123"; SharedPreferences.Editor edit = sp.edit(); edit.putString("quarter", q); edit.commit(); SettingsActivity.this.finish(); } }); changeQuarter.show(); } }); }
From source file:com.aniruddhc.acemusic.player.WelcomeActivity.GooglePlayMusicFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;//www . j a va 2s. c om View rootView = (View) inflater.inflate(R.layout.fragment_welcome_screen_5, null); welcomeHeader = (TextView) rootView.findViewById(R.id.welcome_header); welcomeHeader.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Light")); welcomeText1 = (TextView) rootView.findViewById(R.id.welcome_text_1); welcomeText1.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular")); googlePlayMusicDisclaimer = (TextView) rootView.findViewById(R.id.google_play_music_disclaimer); googlePlayMusicDisclaimer.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular")); radioGroup = (RadioGroup) rootView.findViewById(R.id.google_play_music_radio_group); final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext()); final Account[] accounts = accountManager.getAccountsByType("com.google"); final int size = accounts.length + 1; //We're adding 1 here to account (no pun intended) for the extra "Don't use Google Play Music" option. final RadioButton[] radioButton = new RadioButton[size]; //Add a new radio button the group for each username. for (int i = 0; i < size; i++) { radioButton[i] = new RadioButton(getActivity()); radioGroup.addView(radioButton[i]); //The first radio button will always be "Don't use Google Play Music". if (i == 0) { radioButton[i].setChecked(true); radioButton[i].setText(R.string.dont_use_google_play_music); } else { radioButton[i].setText(accounts[i - 1].name); } radioButton[i].setTag(i); radioButton[i].setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular")); } radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int radioButtonID = group.getCheckedRadioButtonId(); View radioButton = group.findViewById(radioButtonID); int index = group.indexOfChild(radioButton); if (index != 0) { account = accounts[index - 1]; mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name) .commit(); AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, getActivity(), true, account.name); task.execute(); } else { mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", "").commit(); mApp.getSharedPreferences().edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit(); } } }); return rootView; }
From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeRadioGroupFragment.java
@Nullable @Override//from w w w . j a v a 2s . c o m @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:com.example.karspoolingapp.RouteByHitchhikerCar.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.routebyhitchhiker); Intent intent = getIntent();/* w w w. jav a 2s .c om*/ Bundle bundle = intent.getExtras(); new_license_number = bundle.getString("pre_end_point"); //session_username = session.getUsername(); System.out.println("nayaaa licnse number" + new_license_number); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); // code for dynamic radio button generation final RadioButton[] rb = new RadioButton[100]; rl = (RelativeLayout) findViewById(R.id.rl); rg = new RadioGroup(this); // Building Parameters List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("car_number", new_license_number)); System.out.println(params); json = jsonParser.makeHttpRequest(READ_COMMENTS_URL2, "POST", params); params.clear(); System.out.println(json); try { jsonTripDetails = json.getJSONArray("route"); System.out.println(jsonTripDetails); int k = jsonTripDetails.length(); if (k > 0) { for (int i = 0; i < jsonTripDetails.length(); i++) { JSONObject c = jsonTripDetails.getJSONObject(i); String parent_username_str = c.getString("username"); String route = c.getString("route"); String timing = c.getString("timing"); String seating = c.getString("seating_capacity"); rb[i] = new RadioButton(this); rg.addView(rb[i]); rb[i].setText(parent_username_str + "," + route + "," + timing + "," + seating); params.clear(); } rl.addView(rg); rl.setPadding(50, 50, 50, 50); } else { Toast.makeText(RouteByHitchhikerCar.this, "No Trip available on these routes", Toast.LENGTH_LONG) .show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } addListenerOnButton(); }
From source file:com.landenlabs.all_UiDemo.frag.RadioBtnFrag.java
private void addTabBar(RadioGroup tabHolder, float weight, int padding) { final int maxTabs = 4; // tabHolder.removeAllViews(); int[][] states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }; ColorStateList colorStateList = new ColorStateList(states, new int[] { 0xff00ff00, 0x80ff0000 }); RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, weight); /*/*from w ww. ja v a 2 s . c o m*/ ViewOutlineProvider outlineBoundary; if (Build.VERSION.SDK_INT >= 21) { outlineBoundary = new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setRect(0, 0, 200, 60); // view.getMeasuredWidth(), view.getMeasuredHeight()); } }; } */ String[] pageNames = new String[] { "Home", "Map", "Hourly", "Daily" }; int tabCnt = 0; for (String pageName : pageNames) { RadioButton button = new RadioButton(tabHolder.getContext()); String resName = "tab_" + pageName.toLowerCase(); int resID = getResources().getIdentifier(resName, "drawable", this.getContext().getPackageName()); Drawable tabBtnIcon = getResources().getDrawable(resID); if (tabBtnIcon != null) { if (tabBtnIcon != null && Build.VERSION.SDK_INT >= 21) { tabBtnIcon.setTintMode(PorterDuff.Mode.MULTIPLY); tabBtnIcon.setTintList(colorStateList); } else { tabBtnIcon = DrawableCompat.wrap(tabBtnIcon); DrawableCompat.setTintList(tabBtnIcon.mutate(), colorStateList); DrawableCompat.setTintMode(tabBtnIcon.mutate(), PorterDuff.Mode.MULTIPLY); } // tabBtnIcon = tabHolder.getResources().getDrawable(android.R.drawable.btn_radio); if (Build.VERSION.SDK_INT >= 21) { // Hide standard radio button but leave ripple effect button.setButtonDrawable(null); } else { // Hide standard radio button button.setButtonDrawable(new StateListDrawable()); } button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); /* // button.setBackgroundResource(R.drawable.ripple_boarderless); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); // button.setCompoundDrawablesRelativeWithIntrinsicBounds(null, tabBtnIcon, null, null); // tabBtnIcon.setBounds(0, 0, 50, 100); // img.getMinimumWidth(), img.getMinimumHeight()); // button.setCompoundDrawables(null, tabBtnIcon, null, null); } else { button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); } */ button.setBackgroundResource(R.drawable.ripple_boarderless); button.setPadding(padding, padding, padding, padding); button.setGravity(Gravity.CENTER); button.setTextColor(colorStateList); button.setText(pageName); tabHolder.addView(button, lp); if (++tabCnt == maxTabs) break; } } }
From source file:com.odoo.base.login_signup.SyncWizard.java
private void generateLayout() { LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.layoutLoginConfig); SyncWizardValues syncValues = new SyncWizardValues(); List<SyncValue> syncValuesList = syncValues.syncValues(); if (syncValuesList.size() == 0) { getActivity().finish();/* w ww . jav a 2 s . co m*/ getActivity().startActivity(getActivity().getIntent()); } checkbox = new CheckBox[syncValuesList.size()]; rdoGroups = new RadioGroup[syncValuesList.size()]; TextView[] txvTitles = new TextView[syncValuesList.size()]; int i = 0; int id = 1; Typeface tf_light = Typeface.create("sans-serif-light", 0); Typeface tf_bold = Typeface.create("sans-serif-condensed", 0); for (SyncValue value : syncValuesList) { if (!value.getIsGroup()) { if (value.getType() == SyncValue.Type.CHECKBOX) { checkbox[i] = new CheckBox(scope.context()); checkbox[i].setId(id); checkbox[i].setText(value.getTitle()); checkbox[i].setTypeface(tf_light); layout.addView(checkbox[i]); } else { rdoGroups[i] = new RadioGroup(scope.context()); rdoGroups[i].setId(i + 50); RadioButton[] rdoButtons = new RadioButton[value.getRadioGroups().size()]; int mId = 1; int j = 0; for (SyncValue rdoVal : value.getRadioGroups()) { rdoButtons[j] = new RadioButton(scope.context()); rdoButtons[j].setId(mId); rdoButtons[j].setText(rdoVal.getTitle()); rdoButtons[j].setTypeface(tf_light); rdoGroups[i].addView(rdoButtons[j]); mId++; j++; } layout.addView(rdoGroups[i]); } authorities.put(id + "", value.getAuthority()); i++; id++; } else { txvTitles[i] = new TextView(scope.context()); txvTitles[i].setId(id); txvTitles[i].setText(value.getTitle()); txvTitles[i].setAllCaps(true); txvTitles[i].setPadding(0, 5, 0, 3); txvTitles[i].setTypeface(tf_bold); layout.addView(txvTitles[i]); View lineView = new View(scope.context()); lineView.setBackgroundColor(Color.parseColor("#BEBEBE")); lineView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1)); layout.addView(lineView); } } }
From source file:com.lm.im_huanxin.emoji.EmojiPageFragment.java
protected void initWidget(View rootView) { mPagerFace = (ViewPager) rootView.findViewById(R.id.frag_pager_face); pagePointLayout = (LinearLayout) rootView.findViewById(R.id.frag_point); int total = datas.size(); int pages = total / ITEM_PAGE_COUNT + (total % ITEM_PAGE_COUNT == 0 ? 0 : 1); allPageViews = new GridView[pages]; pointViews = new RadioButton[pages]; for (int x = 0; x < pages; x++) { int start = x * ITEM_PAGE_COUNT; int end = (start + ITEM_PAGE_COUNT) > total ? total : (start + ITEM_PAGE_COUNT); final List<Emojicon> itemDatas = datas.subList(start, end); GridView view = new GridView(aty); EmojiAdapter faceAdapter = new EmojiAdapter(view, itemDatas); view.setNumColumns(7);/*from w w w .j a va2s . c o m*/ view.setHorizontalSpacing(1); view.setVerticalSpacing(1); view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH); view.setCacheColorHint(0); view.setPadding(2, 0, 2, 0); view.setBackgroundResource(android.R.color.transparent); view.setSelector(android.R.color.transparent); view.setVerticalScrollBarEnabled(false); view.setGravity(Gravity.CENTER); view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); view.setAdapter(faceAdapter); view.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (listener != null) { Emojicon emoji = itemDatas.get(position); if (DisplayRules.isDeleteEmojicon(emoji)) { listener.selectedBackSpace(emoji); } else { listener.selectedEmoji(emoji); } } } }); allPageViews[x] = view; RadioButton tip = new RadioButton(aty); tip.setBackgroundResource(R.drawable.selector_bg_tip); RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(8, 8); layoutParams.leftMargin = 10; pagePointLayout.addView(tip, layoutParams); if (x == 0) { tip.setChecked(true); } pointViews[x] = tip; } PagerAdapter facePagerAdapter = new FacePagerAdapter(allPageViews); mPagerFace.setAdapter(facePagerAdapter); mPagerFace.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int index) { pointViews[index].setChecked(true); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); }