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 7014361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:30:41+00:00 2026-05-27T22:30:41+00:00

Im trying to fill a spinner in my application in a different thread. Can

  • 0

Im trying to fill a spinner in my application in a different thread. Can somoene tell me why the following code is not working?

The following code is in the oncreate() method

Thread asyn = new Thread(){
       public void run(){
           try{
               int klok = 0;
               while(klok < 5000){
                   sleep(100);
                   klok = klok + 100;
               }

                try{



                   String[] items = new String[] {"One", "Two", "Three"};
                  ArrayAdapter<String> adapter = new ArrayAdapter<String>(Materiaal.this, android.R.layout.simple_spinner_item, items);
                  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                  spinner1.setAdapter(adapter);



                    }catch(Exception ex){
                       ex.printStackTrace();
                    }finally{
                        //adapter.notifyDataSetChanged();

                    }

           }catch(InterruptedException ex){
               ex.printStackTrace();
           }

       }
    };

    asyn.start();
  • 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-05-27T22:30:41+00:00Added an answer on May 27, 2026 at 10:30 pm

    I think you should use the method runOnUiThread(Runnable r) from the Activity.

    Maybe do something like this

    void run()
    {
        // do stuff
        .
        .
        .
         activity.runOnUiThread(new Runnable()
    
             void run()
             {
                 spinner1.setAdapter(adapter);
             }
    
         );
    }
    

    I hope it helps..

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

Sidebar

Related Questions

Trying to fill the listbox programatically I have written the following code: protected override
I am trying to fill a form in a php application from a C#
I'm am trying to write vba code to fill out web-forms and click buttons
I'm trying to fill devexpress GridControl in background (it's not quick process). I do
I'm trying to fill std::map with std::transform. Next code compiles without error: std::set<std::wstring> in;
I'm trying to get my spinneradapter working. I get no error's but the spinner
I'm trying to fill an array of 20 ints with numbers from 1-20 in
I'm trying to fill-out a form automatically and press a button on that form
I am trying to fill object[] with List<string> but I cannot figure out how
I am trying to fill a table with JSON data. When I run the

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.