Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting values from the adapter onListItemClick
    primarykey
    data
    text
    <p>From my main activity I am inserting string into database and by using cursor adding few values in array adapter,My main class is:</p> <pre><code> public class main{ message = datasource.createMessage(messages,ch,random); ArrayAdapter&lt;Message&gt; adapter = (ArrayAdapter&lt;Message&gt;) getListAdapter(); adapter.add(message); public void onListItemClick(ListView l, View v, int position, long id){ super.onListItemClick(l, v, position, id); Toast.makeText(getActivity(), "position: "+position+" "+"Id: "+id+getListAdapter().getItem(position), Toast.LENGTH_LONG).show(); String str=getListView().getItemAtPosition(position).toString(); } } </code></pre> <p>When I get all the my messages in list I have three values in adapter id, message and threadid and I want to get the value of threadid onListItemClick..How to get the values using adapter in onListItemClick method??Please help and my datasource class where I query database and get object using cursor and add in to adapter..</p> <pre><code> public class datasource{ private String[] allColumns = { MySQLiteHelper.COLUMN_ID,MySQLiteHelper.COLUMN_MESSAGE,MySQLiteHelper.COLUMN_THREADID }; public Message createMessage(String message,char ch,int random) { ContentValues values = new ContentValues(); if(ch=='s') values.put(MySQLiteHelper.COLUMN_STATUS, "s"); if(ch=='r') values.put(MySQLiteHelper.COLUMN_STATUS, "r"); values.put(MySQLiteHelper.COLUMN_PARENTID, 0); values.put(MySQLiteHelper.COLUMN_THREADID, random); values.put(MySQLiteHelper.COLUMN_MESSAGE, message); long insertId = database.insert(MySQLiteHelper.TABLE_NAME, null, values); Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME, allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null, null, null, null); /* Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME, allColumns, null, null, null, null, null);*/ cursor.moveToFirst(); Message newMessage = cursorToMessage(cursor); cursor.close(); return newMessage; } private Message cursorToMessage(Cursor cursor) { Message message = new Message(); message.setId(cursor.getLong(cursor.getColumnIndex("id"))); // message.setparentid(cursor.getLong(1)); message.setmessage(cursor.getString(cursor.getColumnIndex("message"))); message.setthreadid(cursor.getLong(cursor.getColumnIndex("threadid"))); // message.status(cursor.getString(4)); return message; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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