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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:10:05+00:00 2026-06-13T08:10:05+00:00

I have a variable called current which holds the last clicked listview item data.

  • 0

I have a variable called current which holds the last clicked listview item data. The id of this data is to be used to query the db again for movies taht are similar.

The problem that current = id=17985, title=the matrix, year=1999 when all i need is the actual id-number. I have tried to use substring to only use the correct places of the string. This works for the matrix since its id is exactly 5 digits long, but as soon as i try to click movie with higher/lower amount of digits in its id of course it trips up.

String id = current.substring(4,9).trim().toString(); does not work for all movies.

Heres some code:

// search method: this is necessary cause this is the method thats first used and where the variable current is set. This is also the only method using three lines for getting data – id, title and year.

 protected void search() {
        data = new ArrayList<Map<String, String>>();
        list = new ArrayList<String>();
        EditText searchstring = (EditText) findViewById(R.id.searchstring);
        String query = searchstring.getText().toString().replace(' ', '+');
        String text;

        text = searchquery(query);
        try {
            JSONObject res = new JSONObject(text);

            JSONArray jsonArray = res.getJSONArray("movies");

            for (int i = 0; i < jsonArray.length(); i++) {

                JSONObject jsonObject = jsonArray.getJSONObject(i);
                item = new HashMap<String, String>(2);
                item.put("id",jsonObject.getString("id"));
                item.put("title",jsonObject.getString("title"));
                item.put("year", jsonObject.getString("year"));
                data.add(item);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }                   

        aa = new SimpleAdapter(SearchTab.this, data,
                R.layout.mylistview,
                new String[] {"title", "year"},
                new int[] {R.id.text1,
                R.id.text2});
        ListView lv = (ListView) findViewById(R.id.listView1);
        lv.setAdapter(aa);
        lv.setDividerHeight(5); 

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {

                Map<String, String> s = data.get((int) id);
                current = s.toString();
            }});
    }

// similar method: this tries to build a list from the fetched data from “current”-string. As you can see i try to use 4,9 to only get right numbers, but this fails with others. Best would be to only to be ble to get the ID which I cant seem to do. The toast is just to see what is beeing fetched, much like a system out print.

 protected void similar() {
        data = new ArrayList<Map<String, String>>();
        list = new ArrayList<String>();
        String id = current.substring(4,9).trim().toString();
        Toast.makeText(getApplicationContext(), id, Toast.LENGTH_SHORT).show();
        String text;

        text = similarquery(id);
        try {
            JSONObject res = new JSONObject(text);

            JSONArray jsonArray = res.getJSONArray("movies");

            for (int i = 0; i < jsonArray.length(); i++) {

                JSONObject jsonObject = jsonArray.getJSONObject(i);
                item = new HashMap<String, String>(2);
                item.put("title",jsonObject.getString("title"));
                item.put("year", jsonObject.getString("year"));
                data.add(item);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }                   

        aa = new SimpleAdapter(SearchTab.this, data,
                R.layout.mylistview2,
                new String[] {"title", "year"},
                new int[] {R.id.text1,
                R.id.text2});
        ListView lv = (ListView) findViewById(R.id.listView1);
        lv.setAdapter(aa);
        lv.setDividerHeight(5); 

    }
  • 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-13T08:10:06+00:00Added an answer on June 13, 2026 at 8:10 am

    Use current.split(",")[0].split("=")[1]

    edit – assuming of course that id is always the first in the comma separated list and will always be a name value pair delimited by ‘=’

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

Sidebar

Related Questions

Okay so i have a variable called search which holds the string Find this
Maybe you guys can help: I have a variable called $bio with bio data.
I have a PHP-variable called $go_Adress which contains the adress I need to get
I have a variable called $result which should store all the results from my
I have a class called 'subscribedQueue'. This class receives its data via its subscribed
I have a class called Note , which includes an instance variable called time_spent
i have a variable called $eventTimeDate which assemble the date Y-M-D and the time,
I have a variable called posts_object[i].updated_time It's always an utf-timecode. It seems to always
I have a variable called $effectiveDate containing the date 2012-03-26 . I am trying
I have a variable called var in SAS/IML. I want to know how I

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.