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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:35:01+00:00 2026-05-21T03:35:01+00:00

I have a List and each entry has a dynamic count of attributes which

  • 0

I have a List and each entry has a dynamic count of attributes which should show up. Each attribute in a row has a name and a value. This implementation works, but how could I do this in a more efficient way? By now I need to build up the whole list/maps before what is very time-consuming…:

    // get category names
    Map<Long, String> categoriesNames = new HashMap<Long, String>();
    // ...

    // create log-list of maps for SimpleAdapter
    List<Map<String, String>> logsMap = new ArrayList<Map<String, String>>();
    // getAll() is just: db.query(true, TABLE_NAME, null, null, null, null, null, Columns.TIMESTAMP + " desc", null);
    Cursor logs = logDao.getAll();
    try {
        int idIndex = logs.getColumnIndex("_id");
        int timestampIndex = logs.getColumnIndex("timestamp");
        int categoryIdIndex = logs.getColumnIndex("category_id");
        int noteIndex = logs.getColumnIndex("note");
        while (logs.moveToNext()) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("category", categoriesNames.get(logs.getLong(categoryIdIndex)));
            map.put("note", getString(R.string.note) + ": " + logs.getString(noteIndex));
            map.put("timestamp", MyDateUtils.formatDateTime(logs.getLong(timestampIndex)));
            map.put("attributes", attributeLogDao.getAttributesAndValuesByLogId(logs.getLong(idIndex)));
            logsMap.add(map);
        }
    } finally {
        logs.close();
    }

    // Mapping
    String[] from = new String[] { "category", "note", "timestamp", "attributes" };
    int[] to = new int[] {
            R.id.log_list_row_category, R.id.log_list_row_note,
            R.id.log_list_row_datetime, R.id.log_list_row_attributes };

    // ListView Adapter
    SimpleAdapter simpleAdapter = new SimpleAdapter(this,
            logsMap, R.layout.log_list_row, from, to);
    ListView lv = (ListView) this.findViewById(R.id.listView);
    lv.setAdapter(simpleAdapter);

By now I’m building a list to use simpleAdapter. I don’t know how I could use a CursorAdapter or so, because of this line:

map.put("attributes", attributeLogDao.getAttributesAndValuesByLogId(logs.getLong(idIndex)));

(almost last line in the while-loop)

What this call does is:

public String getAttributesAndValuesByLogId(long logId) {
    String attributesString = "";
    Cursor c = db.getSQLiteDatabase().rawQuery("SELECT al." + Columns.VALUE + " AS value, a." + AttributeDao.Columns.NAME + " AS a_name" +
            " FROM " + TABLE_NAME + " AS al, " + AttributeDao.TABLE_NAME + " AS a" +
            " WHERE al." + Columns.LOG_ID + " = " + logId +
            " AND a." + AttributeDao.Columns.ID + " = al." + Columns.ATTRIBUTE_ID +
            " ORDER BY value DESC", null);
    if (c != null && c.moveToFirst()) {
        do {
            attributesString += c.getString(1) + " (" + c.getLong(0) + ")\n";
        } while (c.moveToNext());
        c.close();
    }
    return attributesString;
}

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-05-21T03:35:02+00:00Added an answer on May 21, 2026 at 3:35 am

    To point you in the write direction:

    • Use a SimpleCursorAdapter, leaving most of your code intact.
    • Implement SimpleCursorAdapter.ViewBinder which needs one method, setViewValue.
    • Your implementation of setViewValue will be almost identical to the current body of your while loop.
    • Link the two using SimpleCursorAdapter#setViewBinder.

    The purpose of the view binder is to give you a chance to customize how your columns affect the rows they are bound to. The implementation of setViewValue will look something like:

    if (columnIndex == categoryIdIndex) {
        ... populate view with category name ...
        return true;
    }
    if (columnIndex == timestampIndex) {
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list, each item of which has several things in it, including
I have a List of beans, each of which has a property which itself
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have a table similar to: ID...NAME.....HTMLTEXT 1....Footer....`<b>test</b>` where each entry has some HTML
I have a list with dictionary as elements. Each dictionary has an entry called
I have a List, it has Foo objects, and each Foo has a start
I have a CSV file with several entries, and each entry has 2 unix
I have two Objects, Entries and Samples. Each entry has an associated set of
I have a database where each entry has a file path and a last
I have a listview that has a photograph from the gallery for each entry

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.