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

  • Home
  • SEARCH
  • 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 6882485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:15:32+00:00 2026-05-27T05:15:32+00:00

How to display parameters of an arraylist into a listview I have this array

  • 0

How to display parameters of an arraylist into a listview

I have this array list that is displayed in a listview. right now it works but it shows somekind of random array id looking names thats why i wanted it to use the parameter name of the class which is a string product name.

This is the getters and setters file which includes the product name i want to show for the list

package kfc.project;

public class Product {

String name;
int servingSize;
int calories;
int fat;
int saturatedFat;
int transFat;
int cholesterol;
int sodium;
int carbs;
int fiber;
int sugar;
int protein;
int vitamina;
int vitaminc;
int calcium;
int iron;

public Product (String name, int servingSize, int calories, int fat, int saturatedFat, int transFat, int cholesterol, int sodium, int carbs, int fiber, int sugar, int protein, int vitamina, int vitaminc, int calcium, int iron){
    this.name=name;
    this.calories=calories;
    this.servingSize=servingSize;
    this.fat=fat;
    this.saturatedFat=saturatedFat;
    this.transFat=transFat;
    this.cholesterol=cholesterol;
    this.fiber=fiber;
    this.sugar=sugar;
    this.sodium=sodium;
    this.carbs=carbs;
    this.protein=protein;
    this.vitamina=vitamina;
    this.vitaminc=vitaminc;
    this.calcium=calcium;
    this.iron=iron;
}

public Product (String name, int servingSize){
    this.name=name;
    this.servingSize=servingSize;
}

public String getName() {
    return name;
}

public int getServingSize() {
    return servingSize;
}

public int getCalories() {
    return calories;
}

public int getFat() {
    return fat;
}

public int getSaturatedFat() {
    return saturatedFat;
}

public int getTransFat() {
    return transFat;
}

public int getCholesterol() {
    return cholesterol;
}

public int getSodium() {
    return sodium;
}

public int getCarbs() {
    return carbs;
}

public int getProtein() {
    return protein;
}

public int getFiber(){
    return fiber;
}

public int getSugar(){
    return sugar;
}
public int getVitaminA(){
    return vitamina;
}
public int getVitaminC(){
    return vitaminc;
}
public int getCalcium(){
    return calcium;
}
public int getIron(){
    return iron;
}

}

This is the product list on where i add the products

 package kfc.project;

import java.util.ArrayList;

public class ProductList {
    ArrayList<Product> list;


    public ProductList (){
        list = new ArrayList<Product>();

        //CREATE PRODUCT HERE
        Product chicken;
        list.add(new Product("Chicken", 10, 20, 30, 40, 50, 60, 70, 80, 90, 80,70,60,50,40,30));    

        Product rice;
        list.add(new Product("Rice",11));
    }

    public String[] getNames (){
        int c = 0;
        int size = list.size() - 1;
        String[] names = new String[size];

        while (size >= c) {
            //names.add(list.get(c).getName());
            names[c] = list.get(c).getName();
            c++;
        }

        c = 0;

        return names;
    }

    public ArrayList<Product> getList (){
        return list;
    }

}

Finally, this is where i display the list

    package kfc.project;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class ProductListView extends ListActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {       
        super.onCreate(savedInstanceState);

        final ProductList pl = new ProductList();

        //setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, PRODUCTS));
        setListAdapter(new ArrayAdapter<Product>(this, R.layout.list_item, pl.getList() ));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {

          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(), "View Product", Toast.LENGTH_SHORT).show();

            Product product = pl.getList().get(position);
            // intent stuff for product detail
            Intent intent = new Intent(ProductListView.this, productdetail.class);
            intent.putExtra("name",product.getName());
            intent.putExtra("serving size", product.getServingSize());
            intent.putExtra("calories", product.getCalories());
            intent.putExtra("fat", product.getFat());
            intent.putExtra("saturated fat", product.getSaturatedFat());
            intent.putExtra("trans fat", product.getTransFat());
            intent.putExtra("cholesterol", product.getCholesterol());
            intent.putExtra("sodium", product.getSodium());
            intent.putExtra("carbs", product.getCarbs());
            intent.putExtra("fiber", product.getFiber());
            intent.putExtra("sugar", product.getSugar());
            intent.putExtra("protein", product.getProtein());
            intent.putExtra("vitamina", product.getVitaminA());
            intent.putExtra("vitaminc", product.getVitaminC());
            intent.putExtra("calcium", product.getCalcium());
            intent.putExtra("iron", product.getIron());

            ProductListView.this.startActivity(intent);

            //startActivity(new Intent("kfc.project.productdetail"));
          }

        });

    }



    //TEST STRING ARRAY
    static String[] PRODUCTS = new String[] {
        "Chicken", "Rice", "Coke", "Chicken Burger"
    };



}
  • 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-27T05:15:33+00:00Added an answer on May 27, 2026 at 5:15 am

    Simply in productDetail Activity call getIntent() method which belongs to Activity class, you will get intent from which this activity has beed started. and then you can extract data from it.

    ex.

    Intent intent = getIntent();
    String str = intent.getExtra("name");  
    

    you can then set this text to any TextView.

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

Sidebar

Related Questions

I have a page that accepts parameters from the user. I read this parameter
I display some objects that have thumbnails in two ways: one in a DataGridView,
I was reading this interesting article regarding the display of the memory parameters in
I have a filter and parameters in web.xml web.xml is like this: <filter> <description>
I have an activity in which I display an image that is stored on
I have a calc function in java script that takes three integer parameters, following
Currently i have url parameters like this http://www.website.com/index.php?user&page=edit And in index.php i have set
I have a text field that displays 3 parameters with different formats. It has
I have a method that has 2 output parameters. The method should take an
I have a search function that returns an arraylist of objects to my form.

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.