textView as output


  1. olijf

    olijf Member

    hello all,

    i want to make a textView1 that displays my random generated number when clicked on button1. so that i can build 5 questions with the if element.
    the main question is how do i get my random generated number in a textView?

    I know there is a big chance the random number gen won't work but I am new in the Android scripting and want to discover new things, if you know how to get a random number gen please tell me. but don't put to much effort.

    Code (Text):
    1.  
    2. package EasyApp.randomquestion;
    3.  
    4. import android.os.Bundle;
    5. import android.app.Activity;
    6. import android.view.Menu;
    7. import android.widget.TextView;
    8. import android.widget.Button;
    9.  
    10.  
    11.  
    12. public class MainActivity extends Activity {
    13.  
    14.     TextView textView1;
    15.     Button button1;
    16.    
    17.    
    18.     @Override
    19.     public void onCreate(Bundle savedInstanceState) {
    20.         super.onCreate(savedInstanceState);
    21.         setContentView(R.layout.activity_main);
    22.     }
    23.    
    24.     public final void RandomNumber (String args[], String RandomNumber){
    25.         if (view == button1){
    26.         RandomNumber =("random number:"+ 10 * Math.random());
    27.         TextView text = (TextView) findViewById(R.id.textView1);
    28.         text.setText(RandomNumber);
    29.         }
    30.     }
    31.  
    32.    
    33.  
    34.     @Override
    35.     public boolean onCreateOptionsMenu(Menu menu) {
    36.         getMenuInflater().inflate(R.menu.activity_main, menu);
    37.         return true;
    38.     }
    39. }
    40.  
    41.  
    42.  
    thanks in advance
    - Olijf

    Advertisement
    :
  2. chakdev

    chakdev Member

    Hi Olijf,

    You'll want to attach an OnClickListener to button1. Try to Google for "android button setonclicklistener tutorial". I'm sure you will find something useful.
Loading...

Share This Page