1. Download our Official Android App: Forums for Android!

Apps Ask user to select a random letter

Discussion in 'Android Development' started by DubInTheMiddle, Feb 22, 2016.

  1. DubInTheMiddle

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Feb 22, 2016

    Feb 22, 2016
    5
    0
    5
    Male
    Hi,

    I need to ask a user to select a random letter from the alphabet and then display a success or fail notation if they choose the correct letter.

    At the moment I have the code asking to choose a letter using audio when a button is clicked.

    Has anyone any advice or can point me in the direction to get some?

    Any help is greatly appreciated.
     

    Advertisement

    #1 DubInTheMiddle, Feb 22, 2016
    Last edited: Feb 22, 2016
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    What part of this do you need help with? And some code would be helpful to explain what you have already done.
     
  3. DubInTheMiddle

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Feb 22, 2016

    Feb 22, 2016
    5
    0
    5
    Male
    At the moment I have a button when pressed asks the user to pick a random letter. What I need is for the user to select the letter that was asked and if they guess correct they get a "Well done" message and if fail asked to try again.
    This example only has 6 letters in it.

    Code (Text):
    1.  
    2.  
    3. //On click for the button random letter message
    4.  
    5. public void onClickRandom(View v){
    6.     int rando = (int) (Math.random()*6);
    7.     if(rando == 1){
    8.         play_s.start();
    9.     }else if (rando ==2){
    10.         play_t.start();
    11.     }else if (rando ==3){
    12.         play_p.start();
    13.     }else if (rando ==4){
    14.         play_i.start();
    15.     }else if (rando ==5){
    16.         play_n.start();
    17.     }else {
    18.         play_a.start();
    19.     }
    20.  
    21. }
    22.  
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    Sorry still a bit confused as to what you are asking here. The above code appears to play one of six audio files at random.
    Are you asking how to allow the user to enter a letter? For that you will need an EditText component, which is pretty simple.
    How do you wish to display the 'well done' message? Could be in a popup dialog, or a text box.
     
  5. DubInTheMiddle

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Feb 22, 2016

    Feb 22, 2016
    5
    0
    5
    Male
    The user just needs to select a letter. Please see they attached. It might clear it up a bit.

    Pop up dialogue and play a sound would be what I am aiming for.
     

    Attached Files:

  6. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    With all due respect mate, these things are easily found with Google. Just search for 'Android popup dialog' and you'll get tons of pages telling you how to do it.
    What kind of answers are you expecting here?
     
  7. DubInTheMiddle

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Feb 22, 2016

    Feb 22, 2016
    5
    0
    5
    Male
    It's not just a pop up I am looking for. The letter that is asked needs to matched what is chosen by the user. I'm not sure how to do that.
     
  8. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    So your question is how to compare two char variables? Are you really saying you're not sure how to do that?
     
  9. DubInTheMiddle

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Feb 22, 2016

    Feb 22, 2016
    5
    0
    5
    Male
    I know how to compare chars but what I am doing is comparing the contents of two buttons after they where clicked. So the first button asks a random letter and the user selects the same letter through a different button and they have to match.
     

Share This Page

Loading...