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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:44:04+00:00 2026-06-11T06:44:04+00:00

I have a spinner and a database so when i click the spinner i

  • 0

I have a spinner and a database so when i click the spinner i want to show the value(name) of the contacts in it but in a simple code. so they are separetated javas and xml layouts the spinner is in the (Novamensagem.java novamensagem.xml) and the contacs database is in the (Adicionarcontato.java adicionarcontato.xml) if you can specify and simply the code is better, thanks

    final TextView spinnerContato = (TextView) findViewById(R.id.spinner);
    String[] campos = new String[] {"nome", "telefone"};

    Cursor c = db.query("contatos", campos, null, null, null, null, null);
    c.moveToFirst();
    String lista = "";
    if(c.getCount() > 0) {
        while(true) {
            lista = lista + c.getString(c.getColumnIndex("nome")).toString() + "";
            if(!c.moveToNext()) break;
        }

        spinnerContato.setText(lista);
    }

thats the code but it gives the erros (more explained in comments)
//

the entire code:

ArrayList<String>() list = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.novamensagem);

    db = openOrCreateDatabase("banco.db", Context.MODE_WORLD_WRITEABLE, null);

     SalvaMensagem();

    //Data e Hora
    setCurrentDateOnView();
    addListenerOnButton();
    setCurrentTimeOnView();
    addListenerOnButton2();

    //Spinner
    DadosSpinner();





}





private void DadosSpinner() {
    // TODO Auto-generated method stub

    final TextView spinnerContato = (TextView) findViewById(R.id.spinner);
    String[] campos = new String[] {"nome", "telefone"};

    list = new ArrayList<String>();
    Cursor c = db.query("contatos", campos, null, null, null, null, null);
    c.moveToFirst();
    String lista = "";
    if(c.getCount() > 0) {
        while(true) {
           list.add(c.getString(c.getColumnIndex("nome")).toString());
            if(!c.moveToNext()) break;
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);


    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);


    spinner.setAdapter(adapter);        
    }`

there is.

  • 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-11T06:44:06+00:00Added an answer on June 11, 2026 at 6:44 am

    Check this

    list = new ArrayList<String>();
    Cursor c = db.query("contatos", campos, null, null, null, null, null);
    c.moveToFirst();
    String lista = "";
    if(c.getCount() > 0) {
        while(true) {
           list.add(c.getString(c.getColumnIndex("nome")).toString());
            if(!c.moveToNext()) break;
        }
    
    
    }   
    

    This helps you to get an arrayList of items.

    Next do this

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    
    
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    
    
    spinner.setAdapter(adapter);
    

    Be back if you have any issues

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

Sidebar

Related Questions

I have spinner which I populate from SQLite database. But I want to populate
I have code which retrieves information about players from a MySQL database. I want
I have a spinner that show my data list from a database SQLite.. I
* I have saved some data from spinner in to the database. But I
I have spinner with array list thats work fine, but i want to sort
I want to fetch data from database and display in spinner. but it is
I have a spinner witch is populated from database, when I select an item
I have a Spinner.onItemSelected() method and I want to be able to have an
I have Two spinner(Subject and Chapter),I crate two table(Chapter,subject). I add all subject name
I have one spinner, one button and a ListView. I want to choose item

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.