CheckBox edt; edt = new CheckBox(this); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams ( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ); lp.setMargins(25, 0, 0, 0); // move 25 px to right (increase left margin) edt.setLayoutParams(lp); // lp.setMargins(left, top, right, bottom);
final CheckBox female = new CheckBox(this); female.setText("Female"); female .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); attractedTo.addView(female);
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_driver, container, false); CheckBox check = new CheckBox(getActivity()); check.setText("ff"); check.setPadding(10, 10, 10, 10); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(5, 5, 5, 5); params.gravity = Gravity.NO_GRAVITY; check.setLayoutParams(params); check.setGravity(Gravity.CENTER); LinearLayout lin = (LinearLayout) view.findViewById(R.id.driverLayout); lin.addView(check); return view; }
final EditText et1 = (EditText) findViewById(R.id.editText1); final Button bnext = (Button) findViewById(R.id.button1); // final LinearLayout ll = new LinearLayout(this); LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ll.setOrientation(LinearLayout.VERTICAL); ll.setLayoutParams(params); // bnext.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //getting text from edit text String str_et1 = et1.getText().toString(); do { CheckBox cb = new CheckBox(getApplicationContext()); cb .setLayoutParams(params); cb.setId(i2);//set id to each checkbox cb.setText(str_et1);//set text to each checkbox ll.addView(cb); } while (bnext.isDirty());//add when ever i clicked i2++;//this the counter } });
final LinearLayout lm = (LinearLayout) findViewById(R.id.linearLayout1); LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ll.setWeightSum(1); ll.setOrientation(LinearLayout.HORIZONTAL); final CheckBox box = new CheckBox(this); box.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, .1f)); final TextView tv = new TextView(this); tv.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, .3f)); tv.setText("STD_MOBILE"); LinearLayout l2 = new LinearLayout(this); l2.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, .6f)); l2.setGravity(Gravity.RIGHT); l2.setOrientation(LinearLayout.HORIZONTAL); final Spinner spinner = new Spinner(this); spinner.setOnItemSelectedListener(this); ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, categories); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); spinner.setEnabled(false); l2.addView(spinner); ll.addView(box); ll.addView(tv); ll.addView(l2); lm.addView(ll);
RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams llp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams imageparam = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); ImageView imageView = new ImageView(this); //imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setImageResource(R.drawable.testing); imageView.setPadding(8, 8, 8, 8); imageView.setLayoutParams(imageparam); imageView.setId(1); layout.addView(imageView); RelativeLayout.LayoutParams checkparam = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); CheckBox checkbox = new CheckBox(this); checkparam.addRule(RelativeLayout.BELOW, imageView.getId()); checkparam.addRule(RelativeLayout.CENTER_IN_PARENT, 1); checkbox.setLayoutParams(checkparam); layout.addView(checkbox); setContentView(layout,llp);
CheckBox checkbox = new CheckBox(this); checkbox.setText("completed"); checkbox.setTextSize(TypedValue.COMPLEX_UNIT_PT, 10); checkbox.setTextColor(Color.BLACK); checkbox.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); LinearLayout layout = (LinearLayout)findViewById(R.id.layoutku); layout.addView(checkbox);
ViewGroup.LayoutParams checkbox_relativeParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); checkbox_relativeParams.width = ViewGroup.LayoutParams.MATCH_PARENT; checkbox_relativeParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; CheckBox cb = new CheckBox(getActivity()); cb.setText("I'm dynamic!"); cb.setGravity(Gravity.CENTER); cb.setTextSize(17); cb.setPadding(4,4,4,4); cb.setLayoutParams(checkbox_relativeParams);
cb.setClickable(false); cb.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f)); cb.setGravity(Gravity.CENTER); checkBoxes.add(cb);
for(int counter=0; counter<50; counter++) { booleanList.add(false); CheckBox chkBox = new CheckBox(this); chkBox.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1)); chkBox.setId(counter); chkBox.setOnClickListener(chkBoxOnClickListener); } private OnClickListener chkBoxOnClickListener = new OnClickListener() { @Override public void onClick(View view) { int chkboxID = ((CheckBox)view).getId(); chkBox = (CheckBox) findViewById(chkboxID); if(chkBox.isChecked()) { booleanList.set(chkBox, true); } } }
savepass.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,40)); savepass.setText("Save Username/Password?");
CheckBox chkBox = new CheckBox(this); chkBox.setId(++myid); // AS FOLLOWING, YOU SET SIZE RelativeLayout.LayoutParams chkBoxParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); // OR int width, int hieght); chkBox.setLayoutParams(chkBoxParams); chkBox.setGravity(Gravity.CENTER); chkBox.setTextColor(Color.BLACK); //chkBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); chkBox.setText("Scroll Test"); Your_Main_View_Holder_Layout.addView(chkBox);
List<CheckBox> yourCheckBoxes = new ArrayList<CheckBox>(); List<EditText> yourEditTexts = new ArrayList<EditText>(); try { JSONObject json_row = new JSONObject(json.getString("row" + x)); CheckBox chb = new CheckBox(this); chb.setText(json_row.getString("pregunta")); chb.setId(json_row.getInt("pregunta_verificacion_supervision")); chb.setTextSize(10); chb.setPadding(8, 3, 8, 3); chb.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC); chb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); lm.addView(chb); EditText et = new EditText(this); et.setHint("observaciones"); et.setId(json_row.getInt("pregunta_verificacion_supervision")); et.setTextSize(10); et.setPadding(8, 3, 8, 3); et.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC); et.setInputTyp
RelativeLayout layout = new RelativeLayout(this); CheckBox cb1 = new CheckBox(this); cb1.setId(1); cb1.setText("A"); CheckBox cb2 = new CheckBox(this); cb2.setId(2); cb2.setText("B"); CheckBox cb3 = new CheckBox(this); cb3.setId(3); cb3.setText("C"); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT); layout.setLayoutParams(lp); layout.addView(cb1); lp.addRule(RelativeLayout.BELOW,cb1.getId()); cb2.setLayoutParams(lp); layout.addView(cb2); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);//important lp2.addRule(RelativeLayout.BELOW,cb2.getId());//important cb3.setLayoutParams(lp2);//important layout.addView(cb3);
Private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button); CheckBox txtListChild = (CheckBox) convertView.findViewById(R.id.lblListItem); txtListChild.setText(childText); txtListChild.setLayoutParams(firstParam); txtListChild.setBackgroundColor(color); txtListChild.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if (arg1) { button.setVisibility(View.VISIBLE); } else { button.setVisibility(View.GONE); } } }
editText = new EditText(getContext()); editText.setLayoutParams(layoutParams); checkBox.setLayoutParams(layoutParams); checkBox.setText("Disabled"); FrameLayout dialogView = new FrameLayout(getContext());
int color = Color.argb(255, 255, 255, 255); txtListChild.setText(childText); txtListChild.setLayoutParams(firstParam); txtListChild.setBackgroundColor(color); txtListChild.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
public void startQuizClick() { HashMap<String, String> h1 = new HashMap<>(); for (int i = 0; i < 5; i++) { // cb is custom checkbox CheckBox cb = new CheckBox(this); cb.setLayoutParams(new LinearLayout.LayoutParams(100,100)); cb.setId(i); cb.setEnabled(true); cb.setTextColor(ContextCompat.getColor(Main2Activity.this,R.color.colorAccent)); cb.setText("test"); cb.setTextSize(14); cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Log.e("item checked","ischedked"+isChecked); } }); //linear layout lli.addView(cb); } }
select_checkbox.setLayoutParams(innerParams); select_checkbox.setTextColor(Color.BLACK); select_checkbox.setGravity(Gravity.CENTER);
cb.setClickable(false); cb.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f)); cb.setGravity(Gravity.CENTER); lVer1.addView(cb);