Adding multiple buttons on the fly
问题 I want to add multiple buttons dynamically through the code on button click, I searched many previous posts which shows to add single button, but I need multiple ones. Attached is the sample code. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button b1 = (Button)findViewById(R.id.button1); b1.setOnClickListener(new View.OnClickListener() { @Override public