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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:39:49+00:00 2026-05-27T20:39:49+00:00

I have an application that fetches announcements stored as xml files on a server

  • 0

I have an application that fetches announcements stored as xml files on a server and loads the title and author of each announcement into a ListView item. What I also need to store with each item is the ID of each announcement but I don’t actually need to display it. I thought about maybe storing the ID in the hash map I use to fill the list and then find the associated ID with the title clicked but I think it would be unsafe to use since two announcements could have the same title (and author and date). I also thought about adding an invisible TextView to each item to store the ID but that was causing layout problems. Lastly, I searched around and found setTag() and getTag() which I think would be perfect for what I want to do but I’m not really sure how to use them with SimpleAdapter (I’m relatively new to this…). If the TextView idea is what I need to do (though I doubt it), here is the layout I’m using for each item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
      android:id="@android:id/text1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="6dip"
      android:textAppearance="?android:attr/textAppearanceMedium"/>
    <LinearLayout 
        android:orientation="horizontal"
        android:id="@+id/items"
        android:weightSum="100"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
          android:id="@android:id/text2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="6dip"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:layout_weight="85"/>
        <LinearLayout 
            android:orientation="vertical"
            android:id="@+id/itemCB"
            android:layout_weight="15"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center">
            <CheckBox
                android:id="@+id/cbSelected"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

And I’m using the following adapter to fill the list:

for(int i = 0; i < ann.length; i++)
{
    map = new HashMap<String, String>();
    map.put("line1", ann[i].getTitle());
    map.put("line2", "Posted by: " + ann[i].getAuthor() + "\n" + ann[i].date.toLongString());
    list.add(map);
}
String[] from = { "line1", "line2"};

int[] to = { android.R.id.text1, android.R.id.text2};

SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.twoline_checkbox_id_listitem, from, to);
setListAdapter(adapter);

Thank you for any 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-05-27T20:39:50+00:00Added an answer on May 27, 2026 at 8:39 pm

    Theoretically you could do either approaches and it will probably work without problems. In the long run however, I would say you’ll be better of with a simple entity object and a custom adapter. More specifically, from the looks of it, I would opt for an ArrayAdapter, and you already seem to be using some sort of simple entity object for the array ann.

    There are tons of examples that can show you how to extend ArrayAdapter. The most important part however is the getView() method, which in it’s most basic form could look somewhat like this:

    public View getView(int position, View convertView, ViewGroup parent) {
        View row;
        if (null == convertView) {
            row = mInflater.inflate(R.layout.list_item, null);
        } else {
            row = convertView;
        }
    
        MyObject item = (MyObject) getItem(position);
    
        TextView tv = (TextView) row.findViewById(android.R.id.xxx);
        tv.setText(item.getTitle);
    
        // same for other fields/views; e.g. author, date etc
    
        return row;
    }
    

    In stead of creating a SimpleAdapter, now create an instance of your CustomAdapter, pass it your array (or list) of entity objects, and set the whole as adapter to your list:

    MyObject[] objects = ...
    setListAdapter(new ArrayAdapter<string>(this, R.layout.list_item, objects));
    

    Since you’re now dealing with the objects directly, in stead of first creating a bunch of strings representation out of the different fields, you can also easily access the ‘id’ of every item. Even better, you can add a whole lot of different fields without worrying how it will look like in the list, since the visual representation is determined by what you set (and don’t set) in the getView() method of your adapter.

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

Sidebar

Related Questions

I'm developing an enterprise-like application that fetches data from a remote server. I have
I have a silverlight 3 application, that fetches some simple data from a ms-sql-server
I have application that fetches email configuration settings such as host (SMTP Server name),
I have an application that fetches data from a database and stores it in
I have a web application that fetches a lot of content via ajax. For
I have a C# console application that fetches data from more than 100 servers
I have developed an iPhone application that fetches data from internet. I want to
I have developed an application that fetches the feed from a sever, displays the
I have created an iPhone application which fetches data held on a server in
I have an application that fetches some text from a web page , and

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.