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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:40:39+00:00 2026-06-08T08:40:39+00:00

I’m trying to implement a ListView on my app, but i’m trying to understand

  • 0

I’m trying to implement a ListView on my app, but i’m trying to understand and learn how to achieve it without using XML files, all with java code.

I’m stuck on the inflater part, the mInflater.inflate(); function needs a resource xml file, so, i didn’t understand how to continue without using XML files

I have a ArrayList of strings, and I simply need a ListView that shows a list with these strings of the Arraylist, and a delete Button on the right of the String. If the user press the Button, the item of the List get’s deleted.

Each item of the ListView has two things, a TextView with the String of the ArrayList and a Button to delete it.

If someone can give me code examples i will be grateful.

Thanks

  • 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-08T08:40:40+00:00Added an answer on June 8, 2026 at 8:40 am

    I totally agree with CommonsWare. But the part that you are stuck is the part that you have to create a row “template” for the ListView rows. The inflater is used so as to make a single View out of a complete layout.xml file. So the basic idea is that you create an xml that represents each row and then inflate it through that piece of code.

    In your situation, you need to do that through code. Perhaps add a LinearLayout as a parent with orientation=vertical add some width or height properties and then add 2 TextViews so as to be a title and a subtitle with some additional properties. Then you should add them to the LinearLayout and you there you go.

    Your LinearLayout is a pile of Views that are dynamically created and have the same effect as inflating all the above code through an xml file.

    But I reaaaaally don’t see the point in creating such a fuss over a much faster, easier, straight forwarded, better implemented and not to mention best practice…

    EDIT: Somewhere inside your adapter you have: mInflater.inflate(); with the resource that you mention. As I previously said the resource determines how the “template” for each row would be. So a normal xml file that will determine a list row would be something like this:

    <LinearLayout android:layout_width="fill_parent"
       android:layout_height="wrap_content" android:orientation="vertical" >
       <TextView ... /> <! --some properties you want to set -->
       <TextView ... /> <! --some properties you want to set -->
    </LinearLayout>
    

    This xml produces a 2 line list row for a ListView. With the layout inflater the above xml file returns a View object that contains all the bundle.

    So if you want to create it from code, then the snippet would be:

    LinearLayout layout = new LinearLayout(context);
    //layout set some properties
    TextView title = new TextView(context);
    //title set some properties
    TextView subtitle = new TextView(context);
    //subtitle set some properties
    layout.add(title);
    layout.add(subtitle);
    

    Now instead of inflating the xml to get the contents into a single View object, you have the layout variable in the code snippet that contains all the logic that was previously inflated through the xml.

    If you have created a custom ListView adapter before then you should be familiar with creating a custom list row and how it works.

    EDIT: sample code for the adapter of the ListView

    this is the standart procedure of getView() method of the adapter by inflating a single layout:

    @Override
    public View getView(int position, View view, ViewGroup viewgroup) {
    ViewHolder holder; //our view holder of the row
    if (view == null) {
       view = context.getLayoutInflater().inflate(R.layout.static_layout, null);
       holder = new ViewHolder();
       //set the views of the holder
           view.setTag(holder);
    } else {
       holder = (ViewHolder) view.getTag();
    }
        //rest of implementation of the View
        return view;
    }
    

    dynamic implementation:

    @Override
    public View getView(int position, View view, ViewGroup viewgroup) {
    ViewHolder holder; //our view holder of the row
    if (view == null) {
           LinearLayout layout = new LinearLayout(context);
           //layout set some properties
           TextView title = new TextView(context);
           //title set some properties
           TextView subtitle = new TextView(context);
           //subtitle set some properties
           layout.add(title);
           layout.add(subtitle);
       //CREATING THE LAYOUT THROUGH CODE
    
           view = layout; //INSTEAD OF INFLATING A LAYOUT FOR THE ROW I JUST BINDED IT TO THE RECENTLY CREATED LAYOUT 
       holder = new ViewHolder();
       //bind the views of the holder to the views of the layout
           view.setTag(holder);
    } else {
       holder = (ViewHolder) view.getTag();
    }
        //rest of implementation of the View
        return view;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.