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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:47:39+00:00 2026-06-17T16:47:39+00:00

i have created list linearlayout with my code String[] name = {Chicken, Beef, Milk

  • 0

i have created list linearlayout with my code

String[] name = {"Chicken", "Beef", "Milk" ,"Juice"};
    final Integer[] price = {10, 50, 5, 3};
    final Integer[] qty = {1, 2, 5, 5};

    listOrder.removeAllViews();
    LinearLayout.LayoutParams image = new LinearLayout.LayoutParams(Utility.getDip(175, CartActivity.this), Utility.getDip(70, CartActivity.this));
    LinearLayout.LayoutParams text = new LinearLayout.LayoutParams(Utility.getDip(140, CartActivity.this), Utility.getDip(80, CartActivity.this));
    LinearLayout.LayoutParams textQty = new LinearLayout.LayoutParams(Utility.getDip(100, CartActivity.this), Utility.getDip(80, CartActivity.this));
    LinearLayout.LayoutParams textPrice = new LinearLayout.LayoutParams(Utility.getDip(125, CartActivity.this), Utility.getDip(80, CartActivity.this));
    LinearLayout.LayoutParams textTotal = new LinearLayout.LayoutParams(Utility.getDip(130, CartActivity.this), Utility.getDip(80, CartActivity.this));
    LinearLayout.LayoutParams editImage = new LinearLayout.LayoutParams(Utility.getDip(40, CartActivity.this), Utility.getDip(40, CartActivity.this));
    for(int i = 0; i < 4; i++){
        list = new LinearLayout(ctx);
        list.setOrientation(LinearLayout.HORIZONTAL);
        //if((i % 2) == 0) list.setBackgroundColor(R.color.bg_grey);

        listImage = new ImageView(ctx);
        //listImage.setImageDrawable(getResources().getDrawable(R.drawable.sample_logo_publisher));
        listImage.setBackgroundColor(getResources().getColor(R.color.bg_grey));
        listImage.setAdjustViewBounds(Boolean.TRUE);
        listImage.setScaleType(ScaleType.FIT_XY);

        image.gravity = Gravity.CENTER;
        image.setMargins(Utility.getDip(10, CartActivity.this), 0, Utility.getDip(10, CartActivity.this), 0);
        list.addView(listImage, image);

        listText = new TextView(ctx);
        listText.setText(name[i]);
        listText.setGravity(Gravity.CENTER);
        text.gravity = Gravity.CENTER;
        text.setMargins(Utility.getDip(10, CartActivity.this), 0, 0, 0);
        list.addView(listText, text);

        listQty = new TextView(ctx);
        listQty.setText(qty[i].toString());
        listQty.setGravity(Gravity.CENTER);
        textQty.gravity = Gravity.CENTER;
        textQty.setMargins(Utility.getDip(5, CartActivity.this), 0, Utility.getDip(5, CartActivity.this), 0);
        list.addView(listQty, textQty);

        listPrice = new TextView(ctx);
        listPrice.setText(price[i].toString());
        listPrice.setGravity(Gravity.CENTER_VERTICAL);
        textPrice.gravity = Gravity.CENTER;
        list.addView(listPrice, textPrice);

        Integer total = qty[i]*price[i];
        listTotal = new TextView(ctx);
        listTotal.setText(total.toString());
        listTotal.setGravity(Gravity.CENTER_VERTICAL);
        textTotal.gravity = Gravity.CENTER;
        textTotal.setMargins(Utility.getDip(5, CartActivity.this), 0, Utility.getDip(2, CartActivity.this), 0);
        list.addView(listTotal, textTotal);

        plus = new ImageView(ctx);
        plus.setImageDrawable(getResources().getDrawable(R.drawable.plus));
        plus.setAdjustViewBounds(Boolean.TRUE);
        plus.setScaleType(ScaleType.FIT_XY);
        editImage.gravity = Gravity.CENTER;
        list.addView(plus, editImage);
        final int pos = i;
        plus.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                qty[pos] = qty[pos] + 1;
                listQty.setText(qty[pos].toString());
                listTotal.setText(""+ (qty[pos]*price[pos]));
            }
        });

        minus = new ImageView(ctx);
        minus.setImageDrawable(getResources().getDrawable(R.drawable.min));
        minus.setAdjustViewBounds(Boolean.TRUE);
        minus.setScaleType(ScaleType.FIT_XY);
        editImage.gravity = Gravity.CENTER;
        list.addView(minus, editImage);

        remove = new ImageView(ctx);
        remove.setImageDrawable(getResources().getDrawable(R.drawable.trash));
        remove.setAdjustViewBounds(Boolean.TRUE);
        remove.setScaleType(ScaleType.FIT_XY);
        editImage.gravity = Gravity.CENTER;
        list.addView(remove, editImage);

        listOrder.addView(list);
    }

I want to add quantity when onclick on plus image. But when i clicked plus image in the list, textQty changed in end of the list, not in the same list that I have clicked the image.

how to fix my code?

  • 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-17T16:47:40+00:00Added an answer on June 17, 2026 at 4:47 pm

    I have resolved my problem. Here is my code …
    I set id in listQty and listTotal

    listQty = new TextView(ctx);
    listQty.setId(99000+i);
    listQty.setText(qty[i].toString());
    listQty.setGravity(Gravity.CENTER);
    textQty.gravity = Gravity.CENTER;
    textQty.setMargins(Utility.getDip(5, CartActivity.this), 0, Utility.getDip(5, CartActivity.this), 0);
    list.addView(listQty, textQty);
    
    listTotal = new TextView(ctx);
    listTotal.setId(98000+i);
    listTotal.setText(total.toString());
    listTotal.setGravity(Gravity.CENTER_VERTICAL);
    textTotal.gravity = Gravity.CENTER;
    textTotal.setMargins(Utility.getDip(5, CartActivity.this), 0, Utility.getDip(2, CartActivity.this), 0);
    list.addView(listTotal, textTotal);
    

    and in clicklistener set variable of listQty and listTotal

    plus = new ImageView(ctx);
    plus.setImageDrawable(getResources().getDrawable(R.drawable.plus));
    plus.setAdjustViewBounds(Boolean.TRUE);
    plus.setScaleType(ScaleType.FIT_XY);
    editImage.gravity = Gravity.CENTER;
    list.addView(plus, editImage);
    final int pos = i;
    plus.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
        // TODO Auto-generated method stub
            listQty = (TextView)findViewById(99000+pos);
            listTotal = (TextView)findViewById(98000+pos);
            qty[pos] = qty[pos] + 1;
            listQty.setText(qty[pos].toString());
            listTotal.setText(""+ (qty[pos]*price[pos]));
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one scroll view with two list Fragments here is the code:
I have created a list view that displays the names and dates of items
I have created a list form that gets attached to a main form in
I have created a custom list as a feature in sharepoint. i need to
I have created a dynamic list picker script using Jquery 1.3 and PHP that
I have created a custom list view, each row has it's own custom selector,
I have dynamically created some list of RadioButtons with some values. pro grammatically I
I have a dynamically created list. Items from the list should be able to
I have created a populated dropdown list in HTML. When the two dropdowns have
I have created a repeat control that list some documents. I would like to

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.