Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid load data from SQLite Database into next activity
    primarykey
    data
    text
    <p>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.</p> <p>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:</p> <pre><code>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&lt;?&gt; parent, View view, int position, long id) { Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class); // summaryIntent.putExtra("SummTopic", value); } }); </code></pre> <p>EDITED: This part is on the next activity. </p> <pre><code>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"); </code></pre> <p>I got an error while retrieving from database:</p> <pre><code>android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0 </code></pre> <p>Please help.</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload