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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:50:29+00:00 2026-05-23T10:50:29+00:00

I need help in creating a custom listview that allows me to have 2

  • 0

I need help in creating a custom listview that allows me to have 2 strings/textviews per row. I have been researching a lot, but I cannot seem to understand how to do this. Any sample code and help would be appreciated. I know how to use simple_list_item_1, but not my own layout.
Thank YOU.
My (Still Non-Functioning) Code

 package com.painLogger;
 //ALL IMPORTS

 public class PainLoggerActivity extends Activity implements OnClickListener,
 OnKeyListener {

     /** Called when the activity is first created. */
     EditText txtItem;
     EditText txtItem2;
     Button btnAdd;
     ListView listItems;
     ArrayAdapter < String > aa;
     List < HashMap < String, String >> painItems = new ArrayList < HashMap < String, String >> ();
     int[] to;
     String[] from;
     SimpleAdapter adapter;


     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);

         txtItem = (EditText) findViewById(R.id.txtItem);
         txtItem2 = (EditText) findViewById(R.id.txtItem2);

         btnAdd = (Button) findViewById(R.id.btnAdd);
         listItems = (ListView) findViewById(R.id.listItems);

         btnAdd.setOnClickListener(this);

         from = new String[] {
             "row_1", "row_2"
         };
         to = new int[] {
             R.id.row1, R.id.row2
         };

         SimpleAdapter adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
             from, to);
         listItems.setAdapter(adapter);
     }

     private void addItem() {
         HashMap < String, String > map = new HashMap < String, String > ();

         map.put("row_1", txtItem.getText().toString());
         map.put("row_2", txtItem2.getText().toString());
         painItems.add(map);
         adapter.notifyDataSetChanged();
     }

     @Override
     public void onClick(View v) {
         if (v == this.btnAdd) {
             addItem();
         }
     }

     @Override
     public boolean onKey(View v, int keyCode, KeyEvent event) {

         if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode ==
             KeyEvent.KEYCODE_DPAD_CENTER) {             this.addItem();

         }
         return false;
     }
 }
  • 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-23T10:50:30+00:00Added an answer on May 23, 2026 at 10:50 am

    With reference to this question, use this code.
    EDIT: Added hashmap definition

    String[] from = new String[] {"row_1", "row_2"};
    int[] to = new int[] { R.id.row1, R.id.row2};
    List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
    
    for (int j = 0; j < sourceObj.length(); j++) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("row_1", sourceObj.data1);
            map.put("row_2", sourceObj.data2);
            fillMaps.add(map);
    }
    
    SimpleAdapter adapter = new SimpleAdapter(context, fillMaps, R.layout.yourlayoutname, from, to);
    mListView.setAdapter(adapter);
    
    • Make your list view which could be a LinearLayout with a couple of TextViews
    • Reference this list layout using R.layout.yourlayoutname in this line SimpleAdapter adapter = new SimpleAdapter(context, fillMaps, R.layout.result, from, to);
    • Pass in your data

    The good thing about this approach is that it avoids you having to create any new objects, and it doesn’t involve much code.

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

Sidebar

Related Questions

I need help creating a .dll file from a custom control so that it
I need help with creating a C# method that returns the index of the
I need a help about creating custom wpf controls.I want to create a template
I have a module that is used by creating a custom class loader. The
I have a very interesting task that I need help with. The description is
I need help creating a batch file that first runs a command on every
i need help creating a count down timer in php. the problem is that
I need a little help creating a catch-all error handling page in my ICEfaces
I am creating some custom controls in WPF and need to therefore create the
I need some help with rally. I'm currently looking at creating a simple app

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.