0
Код ниже является частью моей программы. Когда я нажимаю на кнопку sunday
, я хочу, чтобы были созданы 4 кнопки. Тем не менее, он выходит из строя в addView
части:Добавление динамических кнопок с помощью addView не работает
sunday.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
LinearLayout lay (LinearLayout)v.findViewById(R.id.lay_schedule);
Button btnS1 = new Button(getContext());
Button btnS2 = new Button(getContext());
Button btnS3 = new Button(getContext());
Button btnS4 = new Button(getContext());
btnS1.setText("Add Your Lesson");
btnS2.setText("Add Your Lesson");
btnS3.setText("Add Your Lesson");
btnS4.setText("Add Your Lesson");
lay.addView(btnS1);
lay.addView(btnS2);
lay.addView(btnS3);
lay.addView(btnS4);
}
});