int CHECK_BOX_ID = 1; CheckBox checkBox = new CheckBox(getApplicationContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams (RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.ABOVE, checkBox.getId()); checkBox.setLayoutParams(layoutParams); checkBox.setWidth(getScreenWidth()); checkBox.setId(CHECK_BOX_ID); CHECK_BOX_ID++; checkBox.setText(questions.get(questionId).answers.get(index)); ll.addView(checkBox);
int checkBoxId = 200000; // global variable to count checkboxes for (int i = 0; i < 1000; ++i) { CheckBox box = new CheckBox(this); box.setId(++checkBoxId); }
LinearLayout my_layout = (LinearLayout) findViewById(R.id.test); for (int n = 0; n < listitems.size(); n++) { CheckBox cb = new CheckBox(getApplicationContext()); cb.setId(Integer.parseInt(listitems.get(n).get("cbid"))); cb.setText(listitems.get(n).get("product")); cb.setTextColor(Color.BLACK); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); parms.leftMargin = 2; params.rightMargin = 2; params.topMargin = 2; params.bottomMargin = 2; my_layout.addView(cb,params); }
LinearLayout checkBocContainer= (LinearLayout)findViewById(R.id.checkbox_container); for (int j = 0; j < 5; j++) { CheckBox checkBox = new CheckBox(this); checkBox.setText("Check Box " + String.valueOf(j)); checkBox.setId(j); checkBocContainer.addView(checkBox); }
final LinearLayout ll = (LinearLayout) findViewById(R.id.lila); for (int i = 0; i < items.size(); i++) { CheckBox cb = new CheckBox(this); cb.setText(String.valueOf(items.get(i))); cb.setId(i); ll.addView(cb); }
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 onCreate(Bundle savedInstanceState) { LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout2); //add checkboxes for(int i = 0; i < 6; i++) { CheckBox cb = new CheckBox(this); cb.setText("Dynamic Checkbox " + i); cb.setId(i+6); ll.addView(cb); } }
for(int i=3;i<plates1.length();++i) { final CheckBox cb=new CheckBox(this); JSONObject jObj1 = plates1.getJSONObject(i); String date=jObj1.getString("Name"); cb.setText(date); cb.setId(i); parentView.addView(cb) // you should add it in parent layout }
for (int i = 1; i <= number; i++) { CheckBox ch = new CheckBox(this); ch.setId((row * 2) + i); // Replace the line with //ch.setText(randomString(3)); // with this line ch.setText(names[i]); ll.addView(ch); }
for (int i = 1; i <= number; i++) { CheckBox ch = new CheckBox(this); ch.setId((row * 2) + i); ch.setText(randomString(3)); // Change Here ll.addView(ch); }
for ( int i=0; i<numberOfCheckBoxes; i++ ) { CheckBox ch = new CheckBox(this); ch.setId((row * 2) + i); ch.setText(checkBoxFruits[i]); ll.addView(ch); }
for (int i = 0; i < 20; i++) { CheckBox cb = new CheckBox(this); cb.setId(i); cb.setText("I'm dynamic!"); ll.addView(cb); }
CheckBox cb = new CheckBox(this); cb.setText("Dynamic Checkbox " + i); cb.setId(i+10); yourlayout.addView(cb);
public void addCheckBox(int number) { String[] names = {"Sanket", "Kumar", "Eagle"}; for (int row = 0; row < 1; row++) { LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); for (int i = 1; i <= number; i++) { CheckBox ch = new CheckBox(this); ch.setId((row * 2) + i); if(i != names.length) ch.setText(names[i-1]); else ch.setText("New name"); ll.addView(ch); } ((ViewGroup) findViewById(R.id.radiogroup)).addView(ll); } }
CheckBox checkBox = new CheckBox(this); checkBox.setId(id); checkBox.setText("text");
if(attrs.length() > 0) { ScrollView mScrollView = new HorizontalScrollView(getApplicationContext()); mScrollView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mScrollView.setFillViewport(true); LinearLayout attrControlsSubContainer = new LinearLayout(getBaseContext()); attrControlsSubContainer.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams layoutParams= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); attrControlsSubContainer.setLayoutParams(layoutParams); for(int i=0;i<attrs.length();i++) { CheckBox chkAttribute = new CheckBox(getBaseContext()); chkAttribute.setText(attrs.getJSONObject(i).getString("name")); chkAttribute.setTextColor(Color.BLACK); chkAttribute.setId(attrs.getJSONObject(i).getInt("id")); attrControlsSubContainer.addView(chkAttribute); } mScrollView.addView(attrControlsSubContainer); attributeControlContainer.addView(mScrollView); }
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); } } }
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);
int Array_Count=0; String[] Str_Array; Array_Count=Str_Array.length; LinearLayout my_layout = (LinearLayout)findViewById(R.id.my_layout); for (int i = 0; i < Array_Count; i++) { TableRow row =new TableRow(this); row.setId(i); row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); CheckBox checkBox = new CheckBox(this); checkBox.setOnCheckedChangeListener(this); checkBox.setId(i); checkBox.setText(Str_Array[i]); row.addView(checkBox); my_layout.addView(row); }
for (Answer a : q.getAnswers()) { final CheckBox cb = new CheckBox(this); cb.setId(Integer.valueOf(a.getId())); cb.setText(a.getValue()); cb.setTextColor(fontColor); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ inviCheckox.append("-"+String.valueOf(buttonView.getId())); } }); lCheckList.addView(cb); }