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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:59:09+00:00 2026-05-27T19:59:09+00:00

I’m new, so sorry if this turns out so simple that I should have

  • 0

I’m new, so sorry if this turns out so simple that I should have solved myself. I’ve spent a couple days thinking about it. I’ve researched a ton and searched many other posts here, but no success.

I have a dialog with DatePicker, Buttons, EditText fields, and Spinners. I can populate everything i need from the stored items in my DB to the dialog. But when i try to get the numbers entered into some of the EditText fields, it throws NumberFormatException. I can hard code values into variables to store, and hide my attempt to get the value in a try and it will run fine. The values get stored and when I open the dialog again they populate into the right areas.

Here’s partial code-

        EditText et = new EditText(getContext()); 
        for(int i=0; i<=etcount; i++){
        placed = -1; //reset for next iteration

        //try to get number from edittext
        et.findViewById(i);
        placed = Integer.parseInt(et.getText().toString());

        awake++;
        /*
        try {
            //et.findViewById(i);
            placed = Integer.parseInt(findViewById(i).toString());
            //placed = Integer.parseInt(et.getText().toString());
        } catch(NumberFormatException nfe) {
           System.out.println("Could not parse " + nfe);
        }*/

I commented out the try block cause I wanted to troubleshoot quickly.

etcount variable is initialized at onCreate with -1 value, before getting values from DB. If there are values stored in the DB it gets incremented by 1, then code is called to dynamically add an EditText and Spinner to the layout. Also the EditText id is set to the value of etcount. Here is that code-

//this will be ran when +placement button pressed, or if there are items in db stored
//adds 2 rows to dialog, one for textview to label items, one row for edittext with number
//and spinner with what item it is
private void createTableRow(int numPlaced, int itmPlaced){ 


    etcount++; //used to count how many edittext fields there are so that they can be saved later
    spincount++; //to count how many spinner there are


    tl = (TableLayout)findViewById(R.id.tableLayoutVisit); //the tablelayout name
    //need to create row for textview, then another row for edittext and spinner
    tr1 = new TableRow(this.getContext()); //table row 1, for textview
    tr1.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    TextView tv = new TextView(this.getContext());
    tv.setText("Amount Placed");
    tv.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    tr1.addView(tv); //add textview to tablerow1
    tl.addView(tr1, new TableLayout.LayoutParams( //add row to tablelayout
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));


    tr2 = new TableRow(this.getContext()); //tablerow2: edittext and spinner
    tr2.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));        
    EditText et = new EditText(this.getContext());
    et.setId(etcount);
    et.setInputType(InputType.TYPE_CLASS_NUMBER);
    if(numPlaced!=0){ //if being populated from previous visit  
        et.setText(Integer.toString(numPlaced));
        //et.setText("" +numPlaced);
    }

    //need to have listener to read data
    et.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));


    Spinner spin = new Spinner(this.getContext());
    spin.setId(spincount);
    spinArray = getContext().getResources().getStringArray(R.array.itemplaced);
    ArrayAdapter adapter = new ArrayAdapter(getContext(),
            android.R.layout.simple_spinner_item, spinArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);


    spin.setAdapter(adapter);
    if(itmPlaced!=-1){
        spin.setSelection(itmPlaced); //assign correct value 
    }
    spin.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    tr2.addView(et);
    tr2.addView(spin);


    tl.addView(tr2, new TableLayout.LayoutParams( //add row to tablelayout
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

}

I pass it (0,-1) if it is a new item and not currently stored in DB. Also you probably noticed I forced it to accept TYPE_CLASS_NUMBER. But I don’t think the issue is there. Again, if I hard code values it will save into the DB and the next time I open it it dynamically creates EditText/Spinner row in layout and populates the EditText with the value in the DB.

So… something is wrong with the first section I think, the et.findViewById(i); or placed = Integer.parseInt(et.getText().toString());. The value of “etcount” should be -1 if nothing was populated from DB, and 0 etc(etcount++) each time something is populated from DB.

Sorry if this is longwinded, wanted to be specific. Hope this is enough info! Any help would be great!!! Thanks in advance.

  • 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-27T19:59:10+00:00Added an answer on May 27, 2026 at 7:59 pm

    Try this:

        EditText et = new EditText(this);
    
        for (int i = 0; i <= etcount; i++) {
            placed = -1;
            et = (EditText) this.findViewById(i);
            placed = Integer.parseInt(et.getText().toString());
            //...
        }
    

    It seems to me that I’ve found an error.
    The main problem in your code that you do not assign unique values in setId methods. In your case some editTexts and spins can have the same IDs. This is wrong. Every element must have a unique identifier. This is the first what you should correct in your code.

    After that you can use my approach. But it seems to me that something wrong in this approach. It is not beautiful ) Try to find best practices in this field.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I know there's a lot of other questions out there that deal with this
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.