Lollipop Leak for Sprint Galaxy S5, TWRP for Micromax Canvas Magnus – XDA TV

Android 5.0 Lollipop has been leaked for the Sprint … more

Velocity is Like OpenTable on Steroids

We all enjoy a night out with friends or our significant other from time to time. However, there is … more

Android Lollipop Lands for the Sony Xperia Z Ultra

The undisputed king of the beasts–at least in Sony’s current stable,is the … more

Android 5.0 Lollipop in 3D–EVO 3D, That Is!

It is that time of the year once again. Flowers bloom (or snow falls, depending on which … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

How do you make buttons

OP poyu

22nd April 2014, 11:47 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: Sep 2011
Hello,

I am now making an App for a hospital. I am making the App with Androidstudio but I cant make a button. I have got 4 buttons, but if I click on them they will do nothing. How can I program that if I clicked on them that they will do something? Please help me I can't figure out how could I do this.
Thanks in Advance
Attached Thumbnails
Click image for larger version

Name:	SS.png
Views:	88
Size:	143.7 KB
ID:	2701451  
22nd April 2014, 01:44 PM   |  #2  
arpitkh96's Avatar
Senior Member
Flag panipat
Thanks Meter: 528
 
1,103 posts
Join Date:Joined: Feb 2012
More
Go through the training session on developer.android.com

Sent from my GT-S5570 using XDA Premium 4 mobile app
22nd April 2014, 10:21 PM   |  #3  
SpaceCaker's Avatar
Recognized Themer / Contributor
Flag netherlands
Thanks Meter: 10,809
 
13,386 posts
Join Date:Joined: Mar 2011
More
what i do is use androidnClick="TAG_HIER"

and the make a simple .ethod ( will write / post hier when i am home )

which launches ( apps or sites etc.)

mostly when u type

Button onclick method

on google you will find some gokd tuts

stackoverflow good help aswell






Sent from my S500 using xda app-developers app
23rd April 2014, 04:31 AM   |  #4  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 204
 
258 posts
Join Date:Joined: Nov 2010
More
Quote:
Originally Posted by poyu

Hello,

I am now making an App for a hospital. I am making the App with Androidstudio but I cant make a button. I have got 4 buttons, but if I click on them they will do nothing. How can I program that if I clicked on them that they will do something? Please help me I can't figure out how could I do this.
Thanks in Advance

First go to you activity.java file and initialize a button

Code:
private static Button button1;
Then link it with the button in xml using it's id

Code:
button1= (Button) rootView.findViewById(R.id.button1);
Then add a listener where you define what happens on button press.

Code:
button1.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				system.out.println("Button pressed");
			}
		});
23rd April 2014, 05:02 PM   |  #5  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: Sep 2011
[QUOTE=gh0stslayer;52118919]First go to you activity.java file and initialize a button

Code:
private static Button button1;
Then link it with the button in xml using it's id

Code:
button1= (Button) rootView.findViewById(R.id.button1);
Then add a listener where you define what happens on button press.

Code:
button1.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				system.out.println("Button pressed");
			}
		});
[/QUOTE

Thank you very much, but when I did this it gave me a message that I pressed a button. What I want is that when i press the button that I will go to an other page. A new page. How can I get this done. I appreciate it a lot that you have done this for me
23rd April 2014, 05:17 PM   |  #6  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 204
 
258 posts
Join Date:Joined: Nov 2010
More
[QUOTE=poyu;52131514]
Quote:
Originally Posted by gh0stslayer

First go to you activity.java file and initialize a button

Code:
private static Button button1;
Then link it with the button in xml using it's id

Code:
button1= (Button) rootView.findViewById(R.id.button1);
Then add a listener where you define what happens on button press.

Code:
button1.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
system.out.println("Button pressed");
}
});
[/QUOTE

Thank you very much, but when I did this it gave me a message that I pressed a button. What I want is that when i press the button that I will go to an other page. A new page. How can I get this done. I appreciate it a lot that you have done this for me


to go to another activity ,you have to use intents

inside on click put these lines

Code:
Intent intent = new Intent(this, anotheractivity.class);
startActivity(intent);
if you are using fragments, use getActivity() instead of this.
Sent from my Galaxy Nexus using Tapatalk
Last edited by gh0stslayer; 23rd April 2014 at 05:21 PM.
26th April 2014, 08:56 PM   |  #7  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: Sep 2011
How do you make a button that is only enabled if there is text in the textfields in a fragmentactivityQUOTE=gh0stslayer;52131883]
Quote:
Originally Posted by poyu



to go to another activity ,you have to use intents

inside on click put these lines

Code:
Intent intent = new Intent(this, anotheractivity.class);
startActivity(intent);
if you are using fragments, use getActivity() instead of this.
Sent from my Galaxy Nexus using Tapatalk

26th April 2014, 09:30 PM   |  #8  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: Sep 2011
How do you make a button that is only enabled if there is text in the textfields in a fragmentactivityQUOTE=gh0stslayer;52131883]
Quote:
Originally Posted by poyu



to go to another activity ,you have to use intents

inside on click put these lines

Code:
Intent intent = new Intent(this, anotheractivity.class);
startActivity(intent);
if you are using fragments, use getActivity() instead of this.
Sent from my Galaxy Nexus using Tapatalk

27th April 2014, 07:07 PM   |  #9  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 204
 
258 posts
Join Date:Joined: Nov 2010
More
Quote:
Originally Posted by poyu

How do you make a button that is only enabled if there is text in the textfields in a fragmentactivityQUOTE=gh0stslayer;52131883]

you will have to use onEdittext change listener, here is an example

http://stackoverflow.com/questions/4...anged-listener

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes