FORUMS

XeroAsh Theme for CM12

This theme by XDA Senior Member balrajs99 features a black and slate gray UI that gives your phone a … more

Samsung Galaxy S6 To Receive Major Camera Update

When the Samsung Galaxy S6 and S6 Edge were launched, they became the prime focus for … more

Tactile: An Addicting Game with Beautiful Material Design

The game industry has been around for decades, catering to a wide … more

Android’s Consistency and The User Experience

This is a site of power users, and it is fair to say that most of us are more … more
Post Reply Subscribe to Thread Email Thread

How do you make buttons

22nd April 2014, 10:47 AM |#1  
OP Junior Member
Thanks Meter: 0
 
More
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:	90
Size:	143.7 KB
ID:	2701451  
 
 
22nd April 2014, 12:44 PM |#2  
arpitkh96's Avatar
Senior Member
Flag panipat
Thanks Meter: 578
 
Donate to Me
More
Go through the training session on developer.android.com

Sent from my GT-S5570 using XDA Premium 4 mobile app
22nd April 2014, 09:21 PM |#3  
SpaceCaker's Avatar
Recognized Themer / Contributor
Flag netherlands
Thanks Meter: 10,904
 
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, 03:31 AM |#4  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 236
 
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, 04:02 PM |#5  
OP Junior Member
Thanks Meter: 0
 
More
[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, 04:17 PM |#6  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 236
 
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 04:21 PM.
26th April 2014, 07:56 PM |#7  
OP Junior Member
Thanks Meter: 0
 
More
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, 08:30 PM |#8  
OP Junior Member
Thanks Meter: 0
 
More
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, 06:07 PM |#9  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 236
 
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