View checkBoxView = View.inflate(this, R.layout.checkbox, null); CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox); checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Save to shared preferences } }); checkBox.setText("Text to the right of the check box."); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(" MY_TEXT"); builder.setMessage(" MY_TEXT ") .setView(checkBoxView) .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Uri uri = Uri.parse("market://details?id=MY_APP_PACKAGE"); Intent intent = new Intent (Intent.ACTION_VIEW, uri); startActivity(intent); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).show();
final LinearLayout attractedTo = (LinearLayout) findViewById(R.id.register_attracted_to); final CheckBox male = new CheckBox(this); male.setText("Male"); male.setTextColor(getResources().getColor(R.color.foreground_text)); attractedTo.addView(male); final CheckBox female = new CheckBox(this); female.setText("Female"); female.setTextColor(getResources().getColor(R.color.foreground_text)); attractedTo.addView(female);
/** * Creates a check box with the specified text label. * * @param label the check box's label * @param dir the text's direction. Note that {@code DEFAULT} means direction * should be inherited from the widget's parent element. */ public CheckBox(String label, Direction dir) { this(); setText(label, dir); }
/** * Creates a check box with the specified text label. * * @param label the check box's label */ public CheckBox(String label) { this(); setText(label); }
b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for(int i = 0; i < 20; i++) { CheckBox cb = new CheckBox(getApplicationContext()); cb.setText("I'm dynamic!"); ll.addView(cb); } } });
/** * Creates a label with the specified text and a default direction estimator. * * @param label the check box's label * @param directionEstimator A DirectionEstimator object used for automatic * direction adjustment. For convenience, * {@link #DEFAULT_DIRECTION_ESTIMATOR} can be used. */ public CheckBox(String label, DirectionEstimator directionEstimator) { this(); setDirectionEstimator(directionEstimator); setText(label); }
/** * Creates a check box with the specified text label. * * @param label the check box's label * @param asHTML <code>true</code> to treat the specified label as html */ public CheckBox(@IsSafeHtml String label, boolean asHTML) { this(); if (asHTML) { setHTML(label); } else { setText(label); } }
/** * Creates a check box with the specified text label. * * @param label the check box's label */ public CheckBox(String label) { this(); setText(label); }
/** * Creates a check box with the specified text label. * * @param label the check box's label * @param dir the text's direction. Note that {@code DEFAULT} means direction * should be inherited from the widget's parent element. */ public CheckBox(String label, Direction dir) { this(); setText(label, dir); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); CheckBox checkBox = (CheckBox) menu.findItem(R.id.menuShowDue).getActionView(); checkBox.setText("Sample Text"); return true; }
btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for(int i = 0; i < 20; i++) { CheckBox cb = new CheckBox(getApplicationContext()); cb.setText("I'm dynamic!"); lil.addView(cb); } } });
ArrayList<CheckBox> checkboxes = new ArrayList<CheckBox>(); for (String s : dataArray) { CheckBox cBox = new CheckBox(myContext); //or inflate it from xml if you have a defined style cBox.setText(s); checkboxes.add(cBox); }
showFurtherErrors.setText("Show further errors"); showFurtherErrors.getElement().getStyle().setFontSize(10, Style.Unit.PT); showFurtherErrors.getElement().getStyle().setColor("white");
TextView message = new TextView(context); message.setText(context.getString(R.string.msg_photo_caution)); CheckBox do_not_show_this_again = new CheckBox(context); do_not_show_this_again.setText(context.getString(R.string.msg_dont_show_again)); LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(message); layout.addView(do_not_show_this_again); dialogBack.setView(layout);
LinearLayout my_layout = (LinearLayout)findViewById(R.id.my_layout); button.setOnClickListener(new onClickListener(){ void onClick(){ CheckBox checkBox = new CheckBox(this); checkBox.setText(Str_Array[i]); my_layout.addView(checkBox); } });
private LinearLayyout ll = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.leftMargin = 123;; CheckBox cb; for(int i = 0; i < 10; i++) { cb = new CheckBox(this); cb.setText(categoryListArray[i]); ll.addView(cb, ll); }
if (type == TYPE.CHECKBOXES){ LinearLayout myPanel = new LinearLayout(this); for (int i = 0; i < n ; i++){ CheckBox chk=new CheckBox(this); chk.setText("Hello"); myPanel.addView(chk); } myRootPanel.addView(myPanel); }
for (int i = 0; i < items.size(); i++) { CheckBox cb = new CheckBox(this); cb.setText(String.valueOf(items.get(i))); cb.setId(items.get(i)); ll.addView(cb); }
@Override public void setLabel(String label) { if (useCheckBoxWidgetLabel) { asCheckBox().setText(label); } else { super.setLabel(label); } }
TableLayout tl=new TableLayout(this); TableRow tr=new TableRow(this); CheckBox chk=new CheckBox(this); chk.setText("Hello"); tr.addView(chk); tl.addView(tr); setContentView(tl);