Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9176731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:10:27+00:00 2026-06-17T17:10:27+00:00

First of all, I’m using Andorid and Java only for a week and I’m

  • 0

First of all, I’m using Andorid and Java only for a week and I’m a total newbie.

I need to know which button user clicked and then compare it with good or bad answer.

Here is the code

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.questions);



        Integer[] flags = {
            R.drawable.flag_albania,
            R.drawable.flag_andorra,
            R.drawable.flag_angola,
            R.drawable.flag_avganistan,

        };

        String[] questions = {
            "What is the flag of Albania",
            "What is the flag of Andorra",
            "What is the flag of Angola",
            "What is the flag of Avganistan",

        };



        TextView tv = (TextView) findViewById(R.id.textView1);
        int arraySize = flags.length;
        Random rand = new Random();

        ImageButton button1 = (ImageButton) findViewById(R.id.imageButton1);
        int index = rand.nextInt(arraySize);
        int questionIndex1 = index;
        button1.setImageResource(flags[index]);
        flags[index] = flags[--arraySize];

        ImageButton button2 = (ImageButton) findViewById(R.id.imageButton2);
        index = rand.nextInt(arraySize);
        int questionIndex2 = index;
        button2.setImageResource(flags[index]);
        flags[index] = flags[--arraySize];

        ImageButton button3 = (ImageButton) findViewById(R.id.imageButton3);
        index = rand.nextInt(arraySize);
        int questionIndex3 = index;
        button3.setImageResource(flags[index]);
        flags[index] = flags[--arraySize];

        ImageButton button4 = (ImageButton) findViewById(R.id.imageButton4);
        index = rand.nextInt(arraySize);
        int questionIndex4 = index;
        button4.setImageResource(flags[index]);
        flags[index] = flags[--arraySize];

        Integer[] question = {
                questionIndex1,
                questionIndex2,
                questionIndex3,
                questionIndex4
        };

        int questionArraySize = question.length;

        int questionArray = rand.nextInt(questionArraySize);

        tv.setText(questions[question[questionArray]]);

My idea is to compare questionIndex that is randomly selected to a button id but I really don’t know how to implement it. Every help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:10:29+00:00Added an answer on June 17, 2026 at 5:10 pm

    Use this reduced code

    ImageButton button1,button2,button3,button4;
                ImageButton imagebuttons[]={ button1,button2,button3,button4};
            int ids[]={R.id.imageButton1,R.id.imageButton2,R.id.imageButton3,R.id.imageButton4};
    
            for(final int i=0;i<imagebuttons.length;i++)
            {
                imagebuttons[i]=(ImageButton) findViewById(ids[i]);
        int index=rand.nextInt(arraySize);
                 imagebuttons[i].setImageResource(flags[index]);
                 flags[index] = flags[--arraySize];
                 indexes.put(i,index);
                imagebuttons[i].setOnClickListener(new View.OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        if( questionArray==indexes.get(i))
                        {
    
                        }
    
                    }
                });
    

    I hope this will help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I know how to build a Java application. But I have
First of all, I'm quite new to the Android and JAVA world (coming from
first of all i would like to say i know its probably an easy
First of all I don't know If controller is the right word. What I
First all, I am still learning CakePHP and I am close to ZERO using
First of all, I'm using ARC. If I have a class that, for example,
i have this code which i use in order to extract first all users
I have this code below, with which I select first all id's from table
First of all, I'm a complete newbie when it comes to VBA, but unfortunately
First of all, I am using this gemfile here : https://github.com/ryanwkan/covetous After initializing my_profile

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.