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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:03:59+00:00 2026-06-07T05:03:59+00:00

Using Android (Eclipse) I am trying to read a .csv file and dynamically populate

  • 0

Using Android (Eclipse) I am trying to read a .csv file and dynamically
populate a Spinner using Scanner. Have tried many methods with the same result.
Emulator shows Spinner but only the last comma and price are populated. Also need to
store all three variables in array and retrive them when Spinner selection is made
in order to populate EditText fields. Any assistance would be greatly appreciated…

Data file records:

4,Aluminum Cans,.55 5,Vehicle with cat convertor,9.00 18,Brass ( Irony Red/Yellow ),.20 1001,Deduction Customer # Look-Up,-2.00

Java:

public class BRprogramActivity extends Activity {
    private static final String TAG = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //
        Button addButton;
        Button editButton;
        Button sendButton;
        //  
        Spinner array_spinner;
        //
        //      activate soft Keyboard
        this.getWindow().setSoftInputMode
        (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
        //
        //      .csv comma separated values file
        //        
        try {
            Scanner scanner = new Scanner(getResources().openRawResource(R.raw.brdata));  
            //         
            while (scanner.hasNext()) {
                String data = (scanner.next());
                String [] values = data.split(",");
                item = values[0];              
                description = values[1];
                price = values[2];    
                //  
                array_spinner = (Spinner)findViewById(R.id.spinner1);         
                ArrayAdapter<String> adapter = new ArrayAdapter<String>
                (this,android.R.layout.simple_spinner_item,values);
                array_spinner.setAdapter(adapter); 
            }       
            scanner.close();

        }   catch (Exception e) {
            Log.e(TAG, "Exception: "+Log.getStackTraceString(e));
        }
        //
        addButton = (Button) findViewById(R.id.addbutton);

        addButton.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Log.v("test", "ADD button clicked");
            }
        });
        //
        editButton = (Button) findViewById(R.id.editbutton);

        editButton.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Log.v("test", "EDIT button clicked");
            }
        });    
        //
        sendButton = (Button) findViewById(R.id.sendbutton);

        sendButton.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Log.v("test", "SEND button clicked");
            }
        });
    }
}  
  • 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-07T05:04:01+00:00Added an answer on June 7, 2026 at 5:04 am

    If you want to display each row of your CSV on one row in the spinner, try this:

    List<String> list = new ArrayList<String>();
    while (scanner.hasNext()) {
        list.add(scanner.next());
    }
    
    array_spinner = (Spinner)findViewById(R.id.spinner1);         
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
    array_spinner.setAdapter(adapter); 
    

    Though has poor readability for the ordinary user, perhaps you only want to display the description and price:

    List<String> list = new ArrayList<String>();
    while (scanner.hasNext()) {
        String data = scanner.next();
        String [] values = data.split(",");
        list.add(values[1] + "  $" + values[2]);
    }       
    

    Your posted method only showed the last CSV line, because you were creating a new ArrayAdapter for each line in the CSV and overriding the previous adapter that you had created.

    By storing the Scanner’s results in a List and moving the adapter’s definition out of the Scanner loop, you should be able to see results like you had hope.

    Addition from comments

    An OutOfBounds exception with length=2, index=2 suggests that at least one row in your real CSV only has two values (one comma). To help you find that row try this:

    if(values.length != 3)
        Log.v("Example", "Malformed row: " + data);
    else
        list.add(values[1] + "  $" + values[2]);
    

    Also, I neglected to mention that you are not setting a drop down layout for your Spinner. This will not cause the app to crash, but this creates the standard user interface:

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Google's SDK Tutorial for Android using Eclipse. I was able
I am trying to create an android project using eclipse IDE,its created successfully but
I'm a novice programmer and I'm trying to learn Android coding using Eclipse. This
I'm trying to obfuscate my android application using proguard and ant ( eclipse +
I'm using eclipse + android SDK. I'm trying to create a table with data
I am trying to debug the android source using Eclipse by following the instructions
Hi im trying to create a simple android app using the Eclipse IDE, all
I am using Eclipse Indigo on Windows 7 and have repeatedly tried to install
i am trying to create a simple android app using eclipse and android sdk
I'm trying to get a PhoneGap application for Android running (using Eclipse with PhoneGap

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.