开发者

How to draw a JButton in Android [closed]

开发者 https://www.devze.com 2023-03-20 03:11 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help cen开发者_StackOverflowter. Closed 11 years ago.

Which class should I use in an Android program so that when it gets 1 it draws a button or textfield, when it gets 0 it does not draw anything. There is a class in Java that can perform this functionality? I want that when I get 1 it shoud draw button.


Android doesn't use JButtons, it uses it's own Button widget: http://developer.android.com/reference/android/widget/Button.html


Both JButton and JTextArea etc, etc extend JComponent. To draw any JComponent you need JContainer. There are a lot: JPanel, JFrame etc.

So in simple case just create your container, your component and add component to container.

void foo(int i) {
JFrame f = new JFrame();
f.setSize(200, 200);
if (i == 1) {
    f.add(new JButton("aaaaa"));
} else if (i == 2) {
    f.add(new JTextField());
}
}
0

精彩评论

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

关注公众号