Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 4.58 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android Quote app, next and back buttons
  2. package me.me.quote;
  3.  
  4.  
  5. public class Startme extends Activity {
  6.  Random gen= new Random();
  7. int num;
  8.  
  9.  String[] quotes = new String[15];
  10.  
  11.  
  12.  
  13.  
  14.  
  15. public void next(View N){
  16.          quotes[0]= "Love is timeless";
  17.             quotes[1]= "I hate you";
  18.             quotes[2]= "arggg!";
  19.             quotes[3]= "The end is near";
  20.             quotes[4]= "Leave be";
  21.  
  22.             if(num == 5){
  23.                 num =0;}
  24.  
  25.  
  26.  
  27.            TextView text = (TextView) findViewById(R.id.Quote);
  28.            text.setText(quotes[num++]);
  29.  
  30.  
  31.  
  32.            TextView number = (TextView) findViewById(R.id.Qn);
  33.             number.setText(""+num);
  34.  
  35.         }
  36. public void back(View B){
  37.  
  38.  quotes[0]= "Love is timeless";
  39.    quotes[1]= "I hate you";
  40.    quotes[2]= "arggg!";
  41.    quotes[3]= "The end is near";
  42.    quotes[4]= "Leave be";
  43.  
  44.  TextView text = (TextView) findViewById(R.id.Quote);
  45.  text.setText(quotes[num--]);
  46.  
  47.  TextView number = (TextView) findViewById(R.id.Qn);
  48.     number.setText(""+num);}
  49.  
  50.  
  51.  
  52.  
  53.   public void rand(View G)  {
  54.  
  55.  num = gen.nextInt(5);
  56.  
  57.   quotes[0]= "Love is timeless";
  58.   quotes[1]= "I hate you";
  59.   quotes[2]= "arggg!";
  60.   quotes[3]= "The end is near";
  61.   quotes[4]= "Leave be";
  62.   TextView text = (TextView) findViewById(R.id.Quote);
  63.   text.setText(quotes[num]);
  64.  
  65. TextView number = (TextView) findViewById(R.id.Qn);
  66. number.setText(""+num);        
  67. }
  68.  
  69.  
  70. @Override
  71. public void onCreate(Bundle savedInstanceState) {
  72.     super.onCreate(savedInstanceState);
  73.     this.setContentView(R.layout.startquotes);
  74.  
  75.     TextView Dark=(TextView)findViewById(R.id.Quote);
  76.     Typeface face=Typeface.createFromAsset(getAssets(), "fonts/font1.ttf");
  77.     Dark.setTypeface(face);
  78.  
  79.  
  80. }
  81.  
  82.  
  83. }
  84.        
  85. <?xml version="1.0" encoding="utf-8"?>
  86.     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  87.         android:layout_width="fill_parent"
  88.         android:layout_height="fill_parent"
  89.         android:orientation="vertical" >
  90.  
  91.         <TextView
  92.             android:id="@+id/textView"
  93.             android:layout_width="wrap_content"
  94.             android:layout_height="50dp"
  95.             android:layout_alignParentTop="true"
  96.             android:text="VISIBLE EVERY TIME"
  97.             android:visibility="visible" />
  98.  
  99.         <Button
  100.             android:id="@+id/back"
  101.             android:layout_width="wrap_content"
  102.             android:layout_alignParentLeft="true"
  103.             android:layout_height="wrap_content"
  104.             android:layout_below="@+id/textView"
  105.             android:text="NEXT" >
  106.         </Button>
  107.  
  108.         <Button
  109.             android:id="@+id/next"
  110.             android:layout_alignParentRight="true"
  111.             android:layout_width="wrap_content"
  112.             android:layout_height="wrap_content"
  113.             android:layout_below="@+id/textView"
  114.             android:text="BACK" >
  115.         </Button>
  116.  
  117.     </RelativeLayout>
  118.        
  119. import android.app.Activity;
  120.     import android.os.Bundle;
  121.     import android.view.View;
  122.     import android.view.View.OnClickListener;
  123.     import android.widget.Button;
  124.     import android.widget.TextView;
  125.  
  126.     public class Test extends Activity {
  127.  
  128.         Button next;
  129.         Button back ;
  130.         TextView quoteText;
  131.         int currentSelectedQuote=0;
  132.         String[] quote={"QUOTE1","QUOTE2","QUOTE3","QUOTE4","QUOTE5",};
  133.  
  134.         @Override
  135.         protected void onCreate(Bundle savedInstanceState) {
  136.             // TODO Auto-generated method stub
  137.             super.onCreate(savedInstanceState);
  138.  
  139.             setContentView(R.layout.text);
  140.  
  141.             quoteText=(TextView)findViewById(R.id.textView);
  142.  
  143.  
  144.             quoteText.setText(quote[currentSelectedQuote]);
  145.  
  146.              next=(Button)findViewById(R.id.next);
  147.  
  148.              next.setOnClickListener(new OnClickListener() {
  149.  
  150.                 @Override
  151.                 public void onClick(View v) {
  152.                     currentSelectedQuote++;
  153.  
  154.  
  155.                     if(currentSelectedQuote == 5){
  156.                         currentSelectedQuote =0;}
  157.  
  158.                     quoteText.setText(quote[currentSelectedQuote]);
  159.  
  160.                 }
  161.             });
  162.              back=(Button)findViewById(R.id.back);
  163.  
  164.              back.setOnClickListener(new OnClickListener() {
  165.  
  166.                 @Override
  167.                 public void onClick(View v) {
  168.  
  169.                     if(currentSelectedQuote==0)
  170.                     {
  171.                         currentSelectedQuote=4;
  172.                     }
  173.                     else
  174.                     {
  175.                     currentSelectedQuote--;
  176.                     }
  177.  
  178.                     quoteText.setText(quote[currentSelectedQuote]);
  179.  
  180.                     // TODO Auto-generated method stub
  181.  
  182.                 }
  183.             });
  184.  
  185.  
  186.  
  187.  
  188.  
  189.         }
  190.  
  191.     }