Bertrand
Apple Fan
Profile
Posts: 163
Reg: Dec 26, 2012
saint-quentin f...
4,680
10/04/15 03:46 AM (8 years ago)

[Android] Blank Screen Button

Hi, I am looking to put a button with an action on it, but I can not find how to tie them. I use Android Studio. thx
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
10/04/15 09:38 AM (8 years ago)
//In, onCreateView method, Under this: View thisScreensView = inflater.inflate(R.layout.cm_autoreach, container, false); //add this: Button but = (Button) thisScreensView.findViewById(R.id.button1); //the id above is the button id button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click, put action under this comment } });
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
10/04/15 12:44 PM (8 years ago)
If you are coming from iOS and are used to draw a line from IB to a method in Objective C, well, that's not how things work in Android. There are no segues in Android. Instead, you connect the button with a listener, through program code only. "Listener" is piece of code that gets executed when the user does something on the screen, for instance, clicks on the button. That is why the name of the listener in the above example is "on click listener". You may want to visit the following site: http://www.mkyong.com/android/android-button-example/ which is shock full of simple examples for Android. Or go to YouTube, tons of videos there about Android, as well. For BT, install the blank screen plugin, enter the button code in there and that will be a start. However, before you do that, change the corresponding XML file, through which you can define the button, somewhat similar to IB in iOS. Even better, find a plugin that already has a button and study the code, both in .java and in .xml files of the same name. Then copy and paste to your new blank screen...
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.