Can anyone suggest how this can be implemented? At least approximately. The user clicks on the checkbox and dynamically creates a button above this foliage. If you clicked on the next checkbox, one more button is created, etc.

cbBuy.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { getProduct((Integer) buttonView.getTag()).selected = isChecked; if (isChecked) { //где-то тут надо что-то делать tv1.setTextColor(Color.parseColor("#006600")); } else { tv1.setTextColor(Color.parseColor("002200")); } } }); 

This is how buttons are created:

 LinearLayout lin = (LinearLayout)findViewById(R.id.Privet); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); for(int i = 0; i < 3; i++){ Button button = new Button(this); button.setText("privet"); button.setLayoutParams(layoutParams); lin.addView(button); } 

In the class where I create the foliage and connect it with my adapter. But I need to somehow bring this code to the adapter.

  • figured out. - urikor
  • in the adapter's constructor, I pass it a LinearLayout. and in the adapter in the change event for the checkbox, I dynamically create the buttons and add them like this: lin.addView (button); but for some reason the code runs twice. why? - urikor

0