How to draw a JButton in Android [closed]
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());
}
}
精彩评论