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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:16:07+00:00 2026-06-03T15:16:07+00:00

I am retrieving the string data from an element clicked in my listview. The

  • 0

I am retrieving the string data from an element clicked in my listview.

The element has two rows, one named “current” and one named “name”.
in my listItemOnClick(), i am getting the item that was clicked, and then doing toString() on it. what i am getting is something like this:

{current=SOMETHING, name=SOMETHING}

My question is how do i separate these? Here is my onclick code:

    protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    Object o = this.getListAdapter().getItem(position);
    String current = o.toString();

    ((TextView) findViewById(R.id.check)).setText(current);
}

I want to disply only the current for example. Thanks!

EDIT

My List Variables:

    static final ArrayList<HashMap<String,String>> listItems = 
        new ArrayList<HashMap<String,String>>();;
SimpleAdapter adapter;

Creating the list:

       for(int i=0; i<num_enter; i++){
    final int gi = i;
    adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current"},  new int[] {R.id.text1, R.id.text2});
    setListAdapter(adapter);
    HashMap<String,String> temp = new HashMap<String,String>();
    temp.put("name", name[i]);
    temp.put("current", "Value: " + Integer.toString(current[i]));
    listItems.add(temp);
    adapter.notifyDataSetChanged();
    }
  • 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-03T15:16:10+00:00Added an answer on June 3, 2026 at 3:16 pm

    You could do it that way (ugly and prone to future error when / if the format changes) – add error checks in case the string does not have the right format:

    String s = "{current=CURRENT, name=NAME}";
    s = s.substring(1, s.length() - 1); //removes { and }
    String[] items = s.split(",");
    String current = items[0].split("=")[1]; //CURRENT
    String name = items[1].split("=")[1]; //NAME
    

    Following your edit, it seems that o is a Map so you could also write (much better):

    Map<String, String> map = (Map<String, String>) this.getListAdapter().getItem(position);
    String current = map.get("current");
    String name = map.get("name");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm retrieving data from Active Directory(name,department,title,company,mail) into a string seperated by commas and I
I'm having trouble retrieving JSONP data from one of my sites. On Site A
I am retrieving data from a database, where the field contains a String with
I'm retrieving data from teamcity webservice in json. One of the data is a
I've been playing around with retrieving data from a string using regular expression, mostly
I'm retrieving data from another database that has already created unique IDs for each
Session[Constant] vs Session[String Literal] Performance I'm retrieving user-specific data like ViewData[CartItems] = Session[CartItems]; with
I am retrieving one query string parameter, and for that my code is <a
I created the following method for retrieving stored settings from the database: public String
I have a database where I store two different kinds of data. One table

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.