Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,784,382 Members 47,807 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:	88
Size:	143.7 KB
ID:	2701451  
 
arpitkh96
Old
#2  
arpitkh96's Avatar
Senior Member
Thanks Meter 376
Posts: 1,088
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 10,622
Posts: 13,256
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
Check My SoundCloud for my music remakes,mixes etc Click Here
Check My Website to find a portfolio and about me Click Here
 
gh0stslayer
Old
#4  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 195
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:
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");
			}
		});
 
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:
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
 
gh0stslayer
Old
(Last edited by gh0stslayer; 23rd April 2014 at 04:21 PM.)
#6  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 195
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:
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
 
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:
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:
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: 195
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


New Nvidia SHIELD Tablet OTA! Moto G 4G Gets Official CyangenMod 11 Nightlies – XDA Developer TV

The Nvidia SHIELD Tablet gets its … more

Prevent Apps from Locking Screen Orientation with HaveOwnOrientation

Most applications on Android play nicely with both landscape and … more

Create Your Own Launcher with HTMLauncher

There are hundreds of launcher replacement applications available for Android. Most of them are … more

First ROMs Appear for the Nvidia Shield Tablet

TheNvidia Shield Tablethas only been available for a little over a month. In that short time, … more