SHARE
TWEET

RandomText

rungene Jan 6th, 2017 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Manifest
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.     package="a100dayschallege.inducesmile.com.randomtext">
  5.  
  6.     <application
  7.         android:allowBackup="true"
  8.         android:icon="@mipmap/ic_launcher"
  9.         android:label="@string/app_name"
  10.         android:supportsRtl="true"
  11.         android:theme="@style/AppTheme">
  12.         <activity android:name=".MainActivity">
  13.             <intent-filter>
  14.                 <action android:name="android.intent.action.MAIN" />
  15.  
  16.                 <category android:name="android.intent.category.LAUNCHER" />
  17.             </intent-filter>
  18.         </activity>
  19.         <activity android:name=".Main2Activity"></activity>
  20.     </application>
  21.  
  22. </manifest>
  23.  
  24. //activity_main.xml
  25. <?xml version="1.0" encoding="utf-8"?>
  26. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  27.     xmlns:tools="http://schemas.android.com/tools"
  28.     android:id="@+id/activity_main"
  29.     android:layout_width="match_parent"
  30.     android:layout_height="match_parent"
  31.     android:paddingBottom="@dimen/activity_vertical_margin"
  32.     android:paddingLeft="@dimen/activity_horizontal_margin"
  33.     android:paddingRight="@dimen/activity_horizontal_margin"
  34.     android:paddingTop="@dimen/activity_vertical_margin"
  35.     tools:context="a100dayschallege.inducesmile.com.randomtext.MainActivity">
  36.  
  37.     <TextView
  38.         android:layout_width="match_parent"
  39.         android:layout_height="wrap_content"
  40.         android:text="Random Text"
  41.         android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
  42.         android:layout_centerHorizontal="true"
  43.         android:paddingTop="100dp"
  44.         android:textAlignment="center"
  45.         android:textSize="30sp"
  46.         android:textColor="#000000"
  47.         android:layout_gravity="center"
  48.         android:id="@+id/textview1"
  49.  />
  50.  
  51.     <Button
  52.         android:text="Activity A Button"
  53.         android:layout_width="match_parent"
  54.         android:layout_height="50dp"
  55.         android:textStyle="bold"
  56.         android:layout_margin="20dp"
  57.         android:background="@color/ButtonColor"
  58.         android:layout_alignParentBottom="true"
  59.         android:layout_marginBottom="40dp"
  60.         android:id="@+id/button_a"
  61.  
  62.         android:onClick="ClickMe"
  63.         />
  64. </RelativeLayout>
  65.  
  66. //Mainactivity.Java
  67. package a100dayschallege.inducesmile.com.randomtext;
  68.  
  69. import android.content.Intent;
  70. import android.support.v7.app.AppCompatActivity;
  71. import android.os.Bundle;
  72. import android.view.View;
  73. import android.widget.TextView;
  74.  
  75. import java.util.Random;
  76.  
  77. public class MainActivity extends AppCompatActivity {
  78.  
  79.     @Override
  80.     protected void onCreate(Bundle savedInstanceState) {
  81.         super.onCreate(savedInstanceState);
  82.  
  83.         setContentView(R.layout.activity_main);
  84.  
  85.         Random random = new Random();
  86.         Integer number = random.nextInt(50);
  87.         TextView textView = (TextView)findViewById(R.id.textview1);
  88.         String my_string = String.valueOf(number);
  89.         textView.setText(my_string);
  90.  
  91.  
  92.     }
  93.     public void ClickMe(View view){
  94.  
  95.         Intent intent = new Intent(MainActivity.this,Main2Activity.class);
  96.         startActivity(intent);
  97.     }
  98.  
  99. }
  100. //activitymain2.xml
  101.  
  102. <?xml version="1.0" encoding="utf-8"?>
  103. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  104.     xmlns:tools="http://schemas.android.com/tools"
  105.     android:id="@+id/activity_main2"
  106.     android:layout_width="match_parent"
  107.     android:layout_height="match_parent"
  108.     android:paddingBottom="@dimen/activity_vertical_margin"
  109.     android:paddingLeft="@dimen/activity_horizontal_margin"
  110.     android:paddingRight="@dimen/activity_horizontal_margin"
  111.     android:paddingTop="@dimen/activity_vertical_margin"
  112.     tools:context="a100dayschallege.inducesmile.com.randomtext.Main2Activity">
  113.  
  114.     <TextView
  115.         android:layout_width="match_parent"
  116.         android:layout_height="wrap_content"
  117.         android:text="Random Text"
  118.         android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
  119.         android:layout_centerHorizontal="true"
  120.         android:paddingTop="100dp"
  121.         android:textAlignment="center"
  122.         android:textSize="30sp"
  123.         android:textColor="#000000"
  124.         android:layout_gravity="center"
  125.         android:id="@+id/textview2"
  126.         />
  127.  
  128.     <Button
  129.         android:text="Activity B Button"
  130.         android:layout_width="match_parent"
  131.         android:layout_height="50dp"
  132.         android:textStyle="bold"
  133.         android:layout_margin="20dp"
  134.         android:background="@color/ButtonColor"
  135.         android:layout_alignParentBottom="true"
  136.         android:layout_marginBottom="40dp"
  137.         android:id="@+id/button_b"
  138.         android:onClick="ClickMeNow"
  139.         />
  140.  
  141. </RelativeLayout>
  142.  
  143. //Main2Activity.java
  144.  
  145. package a100dayschallege.inducesmile.com.randomtext;
  146.  
  147. import android.content.Intent;
  148. import android.support.v7.app.AppCompatActivity;
  149. import android.os.Bundle;
  150. import android.view.View;
  151. import android.widget.TextView;
  152.  
  153. import java.util.Random;
  154.  
  155. public class Main2Activity extends AppCompatActivity {
  156.  
  157.     @Override
  158.     protected void onCreate(Bundle savedInstanceState) {
  159.         super.onCreate(savedInstanceState);
  160.         setContentView(R.layout.activity_main2);
  161.  
  162.         Random random = new Random();
  163.         Integer number = random.nextInt(50);
  164.         TextView textView = (TextView)findViewById(R.id.textview2);
  165.  
  166.         String my_string = String.valueOf(number);
  167.         textView.setText(my_string);
  168.     }
  169.     public void ClickMeNow(View view){
  170.  
  171.         Intent intent = new Intent(Main2Activity.this,MainActivity.class);
  172.         startActivity(intent);
  173.     }
  174. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top