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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:11:24+00:00 2026-06-01T19:11:24+00:00

I’m new to Android and have a simple question. Currently I’m working on a

  • 0

I’m new to Android and have a simple question. Currently I’m working on a products application that allows users to add, remove and browse variety of products. The application uses a predefined XML-based layout file as a template that fills the entire screen to show the current product details. When the user adds a new product, I want to re-use the same layout file but populate it with the new product’s information. Also, I want to keep the previously added products (e.g. an ArrayList) and the user can browse this list by sliding horizontally (left-to-right or right-to-left). Now, what is the best thing to use to represent each product (View, sub-view, …etc.), and how to reuse the same XML-based layout file to display different products’ details. Please excuse my English and thank you in advance for the help

  • 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-01T19:11:26+00:00Added an answer on June 1, 2026 at 7:11 pm

    You can create a new class that extends the ArrayAdapter and then override the getView() method to inflate your custom layout. getView() will return the View for a single row. This way you can reuse your layout. So it will look something like:

    public class ProductAdapter extends ArrayAdapter<Product> {
    
        private LayoutInflater li;
    
        public ProductAdapter(Context context, List<Product> products) {
            super(context, 0, products);
            li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            // Get the product of the position
            Product product = getItem(position);
    
            View v = convertView;
            if ( v == null ) {
               // Your custom layout file for a single row in the list.
                v = li.inflate(R.layout.product_row, null);
            }
    
            // Populate your view here. Use v.findViewById().
    
            return v;
        }
    
    }
    

    To show the list in an ListActivity use:

    // The variable products is your initial list of products.
    ProductAdapter adapter = new ProductAdapter(this, products); 
    setListAdapter(adapter);
    

    When you add a product you can add this to your ArrayAdapter by calling either the adapter.add() (if you want to add your product at the end of the list) or insert() (to specify where in the list of products you want to insert the new product) method on the ProductAdapter. Afterwards you can call adapter.notifyDataSetChanged() to notify your adapter that the data has changed and that the list has to be refreshed.

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

Sidebar

Related Questions

I'm new to android game development. I currently working on a simple android app
I'm really new in Android programming, so I have a simple question getting a
I am new starter android. I have simple question. When I choose date through
I am new to Android. I have tried an sample application for status bar
i am creating a new android application.i am using the table layout. I have
I'm new to android apps development and I have a basic sqlite question. What
I am trying to create a simple 3-D app for android that will have
I have a simple question that boggles me. I am trying to use the
I have a question that seems simple but I cannot figure out what is
I'm currently working my way through the book Teach Yourself Android Application Development in

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.