Stackoverflow has really helped me get to this level. Thank you all.
Basically, I want to get an element (sub-part not the whole data) from the selected item in a ListView. I've read here that it could be done using Cursors but no success. This is the associated snippet:
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Cursor member = (Cursor)parent.getItemAtPosition(position);
Toast.makeText(getApplicationContext(),
"Click ListItem Number "+member.getString(2), Toast.LENGTH_LONG)
.show();
}
});
parent.getItemAtPosition(position)
gives me the (Array, I suppose):
{name="xyz_name", uname="xyz_user", desig="xyz_desig"}
correctly.
I want to, suppose, fetch uname
from this, so, have used Cursor to fetch it but the above snippet is giving the error,
java.lang.ClassCastException: java.util.HashMap cannot be cast to android.database.Cursor
Adding detail: I'm getting the text associated with the listView item correctly. What I actually want a sub-part of the data retrieved. For example the data retrieved is obviously an array containing a name and his role. Now, I just want to fetch the 'role' element in the array. Since, the data is retrieved as an array, what I've searched on net is that I can use Cursors to retrieve different elements. Hope you got me now.
There's seem to be a silly syntax error by my side. If you have any alternatives, please tell.
Thanks :)