+ 1

How to create button in apk android?

Help How to make a button if pressed to generate number 1 and if not pressed to produce 0?

11th Mar 2018, 6:23 AM
Rian Pratama
Rian Pratama - avatar
6 ответов
+ 1
button.setOnClickListener(new View.OnClickListener() { @Override public void onClick (View v) { System.out.println("1") }});
11th Mar 2018, 6:40 AM
Darcia14
Darcia14 - avatar
+ 1
I Edited your program: This example will not run in sololearn (I don`t know why), but with a dedicated environment like Netbeans it will public class Program { public static void main(String[] args) { JFrame trFrame = new JFrame("frame"); // trFrame.setBounds(500,200,280,150); trFrame.setVisible(true); trFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = new Container(); trFrame.add(c); Button button = new Button("button"); button.setBounds(0,0,100,150); c.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("1") } }); } }
11th Mar 2018, 3:38 PM
Darcia14
Darcia14 - avatar
0
sorry.this program use java,php or web in sollo learn?
11th Mar 2018, 2:23 PM
Rian Pratama
Rian Pratama - avatar
0
It is for android as you requested, but can be easily adapted for java: button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("1") } });
11th Mar 2018, 2:27 PM
Darcia14
Darcia14 - avatar
11th Mar 2018, 3:24 PM
Rian Pratama
Rian Pratama - avatar
0
thank you very much friend.
11th Mar 2018, 3:40 PM
Rian Pratama
Rian Pratama - avatar