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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:52:12+00:00 2026-06-15T02:52:12+00:00

I have a listView which loads data from SQLite database and right now I

  • 0

I have a listView which loads data from SQLite database and right now I would want to implement an onclicklistener to the list. When users click on the list, it should bring them to the next activity and load the corresponding data into TextView. My question is how would I pass the data of the list for example it is a list of “Topics” and user click on the topic “My Home”. I want to pass the topic “My Home” to the next activity so that I know which corresponding data to be retrieved respectively.

How do I go about it? Do I “putExtras” to the new Intent? or there is another way. Below are part of my codes which display the listview:

ListView listContent = (ListView) findViewById(R.id.contentlist);
        mySQLiteAdapter = new SQLiteAdapter(this);
        mySQLiteAdapter.openToRead();

        Cursor cursor = mySQLiteAdapter.queueAll();
        startManagingCursor(cursor);

        String[] from = new String[] { SQLiteAdapter.KEY_CONTENT };
        int[] to = new int[] { R.id.text };

        SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor, from, to);

        listContent.setAdapter(cursorAdapter);

        mySQLiteAdapter.close();

        //Onclick ListView setlistener
        listContent.setTextFilterEnabled(true);
        listContent.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class);
//              summaryIntent.putExtra("SummTopic", value);
            }
        });

EDITED:
This part is on the next activity.

Intent i = getIntent();
        extraTopic = i.getStringExtra("SummTopic");

        mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
        Cursor allrows  = mydb.rawQuery("SELECT * FROM "+  TABLE + " WHERE topic = \" " + extraTopic + " \" " , null);

        Integer cindex = allrows.getColumnIndex("topic");
        Integer cindex1 = allrows.getColumnIndex("text1");
        Integer cindex2 = allrows.getColumnIndex("text2");

I got an error while retrieving from database:

android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0

Please help.

Thank you.

  • 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-15T02:52:13+00:00Added an answer on June 15, 2026 at 2:52 am
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class);
                Cursor c = (Cursor)parent.getItemAtPosition(position);
                summaryIntent.putExtra("SummTopic", c.getString(c.getColumnIndex(SQLiteAdapter.KEY_CONTENT)));
                startActivity(summaryIntent);
            }
    

    or you can pass id (summaryIntent.putExtra("SummTopicId", id);) of this row and “ask db” in next Activity for Topic with this id

    EDIT:

    protected void onCreate(Bundle savedInstanceState){
        Intent i = getIntent(); 
        String extraTopic = i.getStringExtra("SummTopic"); 
        //or long extraTopic = i.getLongExtra("SummTopic"); if you put id there (which is better)
            mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
        String[] args = new String[] { extraTopic };
        //or String[] args = new String[] { Long.toString(extraTopic) }; with id version
            Cursor singleRow  = mydb.rawQuery("SELECT * FROM "+  TABLE + " WHERE topic=?" , args);
        //args is better then escaping special chars in query
        //and it should be single row so we've changed var name :)
        if(singleRow.moveToFirst()){ //we should do moveToFirst before we can use Cursor
            Integer cindex = allrows.getColumnIndex("topic");
            Integer cindex1 = allrows.getColumnIndex("text1");
            Integer cindex2 = allrows.getColumnIndex("text2");
            //setup views and stuff ....
        }else{
            Toast.makeText(this, "Oops we did not find topic, detail activity was closed", Toast.LENGTH_SHORT).show();
            finish();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview which loads its data from sqlite database. Each row in
I have a ListView with custom adapter which is populated from local sqlite database.
I have ListView which is saving all data to database. For adding i have
I have a ListView which displays a list of string values. I want to
I have an activity which I want to show ListView with list of topics,
I have a URL which loads about 500 records of data which is taking
I have a activity which showing the 20 items in listview, at bottom list
I have a ListView populated by a SimpleAdapter, which gets values from an ArrayList
i want to do sorting in the listview from code behind, and i have
I have a listview which I would like to fill with self created user

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.