javascript - Buttons to Activities -


i'm new android studio doing best learn it. case came , unfortunately can't find answer though seems basics.

my app starts 3 buttons (workouts, results, info)

f.e when click on "workouts" want activity called workoutsactivity.java has 12 buttons.

when click on "results" want activity activityresults.java etc...

  • what code link these different 3 buttons different 3 activities?
  • do need create 12 new activities buttons in workoutsactivity.java? (is how android works?)

i appreciate help. thanks.

ok, here few concepts need understand before publish source code : layouts, views, activities, intents , events.

views visible ui elements such texts, images, buttons, progress bars, rating bars, etc.

layouts invisible ui elements displays views in defined order such row, column or position relative other views (torightof, toleftof, etc.) called containers.

activities 'page' handle single task. contains views , layouts (and more) , context.

intents kind of bridge go activity other. there lot of things learn them, think bridge.

finally, events way user interacts views : clicks, touches, drag , drop, ... contains listeners , handlers such onclicklistener , onclick. obviously, first 1 listen , second handle event.


package com.learnandroid.myapplication;  import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button;  public class mainactivity extends appcompatactivity {      button mybutton;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          mybutton = (button) findviewbyid(r.id.mybutton);          mybutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  intent = new intent(mainactivity.this, secondactivity.class);                 startactivity(i);              }         });     } } 

mainactivity.java

<?xml version="1.0" encoding="utf-8"?>  <relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.learnandroid.myapplication.mainactivity">      <button         android:id="@+id/mybutton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="my button" />  </relativelayout> 

activity_main.xml

do not forget declare every activity in manifest :

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.learnandroid.myapplication">      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity android:name=".mainactivity">             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity android:name=".secondactivity"></activity>     </application>  </manifest> 

androidmanifest.xml


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -