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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:07:55+00:00 2026-05-21T03:07:55+00:00

I have a class Store.java where I simply store 2 strings and an integer.

  • 0

I have a class Store.java where I simply store 2 strings and an integer. Then I create an ArrayList object of the same. I do this so that I can populate the values from 2 spinners and an edit text into the ArrayList dynamically. I want to get these values displayed in a tabular format. Also I’ve created a subclass of Application so that the ArrayList can be easily updated and retrieved in other Activities. The problem is that when I click on the ‘Bill’ button the dynamic rows are not added to the table layout.

Here is the relevant code:

(MyApp.java)

public class MyApp extends Application {

    ArrayList<store> B = null;

    public ArrayList<store> getState(){
        return B;
    }

    public void setState(ArrayList<store> B){
        this.B = B;
    }
}

(Bill.java)

public class Bill extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.calc);
        ArrayList<store> B = new ArrayList<store>();

        store temp1=null;

        MyApp appState = ((MyApp)getApplicationContext());
        appState.setState(B);
        B = appState.getState();
        TableLayout tl = (TableLayout)findViewById(R.id.myTable);

        for(int i=0;i<B.size();i++)
        {  
            temp1=new store();
            TableRow tr = new TableRow(this);
            tr.setId(100+i);
            temp1=B.get(i);      
            tr.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

            TextView b = new TextView(this);
            b.setId(200+i);
            b.setText(temp1.getPizzaName()); 

            TextView b1 = new TextView(this);
            b1.setText(temp1.getPizzaSize());
            b1.setId(300+i);

            TextView b2 = new TextView(this);
            b2.setText(String.valueOf(temp1.getQuantity()));
            b2.setId(400+i);

            b.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
            tr.addView(b);

            b1.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
            tr.addView(b1);


            b2.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
            tr.addView(b2);

            tl.addView(tr,new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
        }
    }
}
  • 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-21T03:07:56+00:00Added an answer on May 21, 2026 at 3:07 am

    Take a look to your code:

        ArrayList<store> B = new ArrayList<store>();
    
        store temp1=null;
    
        MyApp appState = ((MyApp)getApplicationContext());
        appState.setState(B);
        B = appState.getState();
    

    You create a List, than set it as your state, then retrieve it again.
    How do you want to has some data on it?

    PS: Please follow the code conventions, you code is hard to read.

    Your variable ‘temp’ is initialized once. You should make a new instance every time before add it to the List.

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

Sidebar

Related Questions

Let's say I have a class called Store that has many Employees. My RESTful
I have a class that I want to use to store properties for another
I have a session class that needs to store session information in a MySQL
I have a custom class that implements that IComparable. This class is stored in
I have class method that returns a list of employees that I can iterate
I have two Java class hierarchies that share a common ancestor and implement a
Assume I have a class foo, and wish to use a std::map to store
I have a class in my domain model called JobPlan this class is stored
I have a list of users in local store that I need to update
How do I do that? Like you know in Java, you can use an

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.