Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,743 Members 42,341 Now Online
XDA Developers Android and Mobile Development Forum

How do you make buttons

Tip us?
 
poyu
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: Sep 2011
Default How do you make buttons

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:	87
Size:	143.7 KB
ID:	2701451  
 
arpitkh96
Old
#2  
arpitkh96's Avatar
Senior Member
Thanks Meter 375
Posts: 1,085
Join Date: Feb 2012
Location: panipat
Go through the training session on developer.android.com

Sent from my GT-S5570 using XDA Premium 4 mobile app
 
SpaceCaker
Old
#3  
SpaceCaker's Avatar
Recognized Themer / Contributor
Thanks Meter 10506
Posts: 13,127
Join Date: Mar 2011
Location: netherlands
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
 

My Github Click Here
Github BroadcomCM Click Here
Github CyanoSpaceMod Click Here
Github MSR-Roms Click Here
Check My SoundCloud for my music remakes,mixes etc Click Here
Linux HP-Pavilion-G7 3.11.0-23-generic #40-Ubuntu SMP Wed Jun 4 21:05:23 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
 
gh0stslayer
Old
#4  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 193
Join Date: Nov 2010
Location: Bangalore
Quote:
Originally Posted by poyu View Post
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:
Select Code
private static Button button1;
Then link it with the button in xml using it's id

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

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

			public void onClick(View v) {
				system.out.println("Button pressed");
			}
		});
 
poyu
Old
#5  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: Sep 2011
[QUOTE=gh0stslayer;52118919]First go to you activity.java file and initialize a button

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

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

Code:
Select 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
 
gh0stslayer
Old
(Last edited by gh0stslayer; 23rd April 2014 at 04:21 PM.)
#6  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 193
Join Date: Nov 2010
Location: Bangalore
[QUOTE=poyu;52131514]
Quote:
Originally Posted by gh0stslayer View Post
First go to you activity.java file and initialize a button

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

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

Code:
Select 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:
Select 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
 
poyu
Old
#7  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: 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 View Post


to go to another activity ,you have to use intents

inside on click put these lines

Code:
Select 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
 
poyu
Old
#8  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: 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 View Post


to go to another activity ,you have to use intents

inside on click put these lines

Code:
Select 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
 
gh0stslayer
Old
#9  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 193
Join Date: Nov 2010
Location: Bangalore
Quote:
Originally Posted by poyu View Post
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


TRENDING IN THEMER...