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

  • SEARCH
  • Home
  • 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 8266989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:21:50+00:00 2026-06-08T05:21:50+00:00

I have a Game View which triggers 1 Dialog, from here a second Dialog

  • 0

I have a Game View which triggers 1 Dialog, from here a second Dialog is triggered.

Within this second dialog, I have 2 buttons and 1 spinner. The issue I am having is getting a spinner to appear within my view, with dyamic data.

Essentially, I need to spinner to popup when the button is clicked on and list all the relevent data. I have 3 different ArrayLists (1 String and 2 integers), which hold sepearte information which will need to be dynamically added to each spinner choice e.g.

pt1 -   ArrayLists1
        ArrayLists2
        ArrayLists3
pt2 -   ArrayLists1
        ArrayLists2
        ArrayLists3

Spinner XML layout code:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal">
    <Button android:text="@string/attack" 
            android:id="@+id/Attack" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" />
    <Button android:text="@string/useitem" 
            android:id="@+id/UseItemBtn" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" />
    <Spinner android:text="@string/useitem"
            android:id="@+id/UseItemSpin"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:visibility="gone" />
    <Button android:text="@string/equipweapon" 
            android:id="@+id/EquipWeapon" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
</LinearLayout>

Here is the code that I am currently using to trigger the click of the spinner (the log here is triggered):

import android.widget.AdapterView.OnItemSelectedListener;

@Override
public void onClick(View clicked)
{
    if(clicked.getId() == R.id.UseItemBtn)
    {
        Spinner spinner = (Spinner) findViewById(R.id.UseItemSpin);

        ArrayList<String> arrayList1 = new ArrayList<String>();
        arrayList1.add("test item the first one");
        arrayList1.add("really long list item - section 2 goes here - finally section 3");

        ArrayAdapter<String> adp = new ArrayAdapter<String> (context,android.R.layout.simple_spinner_dropdown_item,arrayList1);
        // APP CURRENTLY CRASHING HERE
        spinner.setAdapter(adp);
       //Set listener Called when the item is selected in spinner
       spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
       {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long arg3) 
            {
                String city = "The city is " + parent.getItemAtPosition(position).toString();
                Toast.makeText(parent.getContext(), city, Toast.LENGTH_LONG).show();
            }

            public void onNothingSelected(AdapterView<?> arg0) 
            {
                // TODO Auto-generated method stub
            }
        });
    }
    BattleRun.show();
}

How can I add the dynamic spinner on this click. On top of this when the spinner is clicked, ideally I would like a submit button within the actual spinner so they can flick through the choices before selecting (which should be visible at all times).

Finally, when the item has been selected in the spinner and submitted the previous dialog will automatically refresh with the new data (this I can do easy enough).

If you require any more code snippets please let me know, any help or guidence would be much appreciated.

Thanks,
L & L Partners

  • 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-08T05:21:51+00:00Added an answer on June 8, 2026 at 5:21 am

    You can use this code to populate your spinner with the string array list –

        public void onClick(View clicked){
        if(clicked.getId() == R.id.Attack){
            Spinner spinner = (Spinner) findViewById(R.id.UseItem);
    
          //Sample String ArrayList
            ArrayList<String> arrayList1 = new ArrayList<String>();
    
            arrayList1.add("Bangalore");
            arrayList1.add("Delhi");
            arrayList1.add("Mumbai");
            ArrayAdapter<String> adp = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_dropdown_item,arrayList1);
            spinner.setAdapter(adp);
    
            spinner.setVisibility(View.VISIBLE);
           //Set listener Called when the item is selected in spinner
           spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
           {
                public void onItemSelected(AdapterView<?> parent, View view,
                        int position, long arg3) 
                {
                    String city = "The city is " + parent.getItemAtPosition(position).toString();
                    Toast.makeText(parent.getContext(), city, Toast.LENGTH_LONG).show();
    
                }
    
                public void onNothingSelected(AdapterView<?> arg0) 
                {
                    // TODO Auto-generated method stub
                }
            });
    
            //BattleRun.dismiss();
            Log.d("Item","Clicked");
    
        }
    }
    

    This code will go inside your layout xml file –

    <!-- Add onClick attribute on this button -->
    <Button android:text="@string/attack" 
            android:id="@+id/Attack" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:onClick="onClick" />
    <Spinner android:text="@string/useitem" 
            android:id="@+id/UseItem" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:visibility="gone" />
    <Button android:text="@string/equipweapon" 
            android:id="@+id/EquipWeapon" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
    

    Note that you are not adding onClick inside the xml file. That’s why your onClick function is not getting called.
    You can also use the string-array in strings.xml file for using static list.

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

Sidebar

Related Questions

I have this game where balloons are coming from bottom and player has to
I have game application (cocos2d) in which, a ball is to be shooted from
I have this: _gameService = new GameService(); ViewBag.Data = _gameService.JoinGame(userID, gameID, whoJoin); return View(Game);
I'm working on a simple 2D game (birds eye view). I have projectiles, which
I am developing a game.I have drawn images on a surface view which is
I want to have a game where the view will move around as the
I have started development on a small 2d adventure side view game together with
Hi i have a custom view running my game. Once the player loses it
Say you're building a Tetris game. As any proper programmer, you have your view
I have written a game (I'll give it the name Gamer) in which I

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.