开发者

How to create multiple buttons at runtime?

开发者 https://www.devze.com 2023-02-28 00:32 出处:网络
In开发者_运维知识库 my Android application, I have to add multiple buttons at runtime at the base of the screen. How can I add onClick listener to each button when adding them?You could create a Linea

In开发者_运维知识库 my Android application, I have to add multiple buttons at runtime at the base of the screen. How can I add onClick listener to each button when adding them?


You could create a LinearLayout or whatever on the Eclipse Designer, and put it at the bottom. About the button creation:

Button b = new Button(this); // Assuming it's in your activity
LinearLayout ll = (LinearLayout)findViewById(R.id.myLayoutAtTheBottom); // It could not be a LinearLayout, of course
ll.addView(b);

And so on for each button.


You can add as many button as you wish at runtime with Button b = new Button(this); code /...:) wts the problem

0

精彩评论

暂无评论...
验证码 换一张
取 消