开发者

How can I dynamically create a button in Android? [duplicate]

This question alr开发者_运维技巧eady has answers here: Closed 10 years ago.

Possible Duplicate:

how to add button dynamically in android?

How can I dynamically create a button in Android?


Firstly add the appropriate import to your Activity:

import android.widget.Button;

Then create a new button object within the onCreate method:

Button myButton = new Button(this);
myButton.setText("Press Me");

Finally add the button to the layout:

LinearLayout layout = (LinearLayout) findViewById(R.id.layout1);
layout.addView(myButton);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜