Reputation: 9
Hi i am new to android programming, i have make an Http post request to get json data from an external sql database and displayed my result in a lisView. i want to be able to retrieve the string value from a clicked item in the listView. Please any help with this will be much appreciated
Upvotes: 1
Views: 4693
Reputation: 2230
I would try something like this, which has worked for me in the past:
String itemValue = (String) listView.getItemAtPosition(position);
This is from within the listView.setOnItemClickListener(new OnItemClickListener()
portion of your code.
If your strings are aggregated into one string, then try this:
//Let itemValue = "item1 item2 item3" for example:
String[] parts = itemValue.split(" ");
String part1 = parts[0]; // item1
String part2 = parts[1]; // item2
Upvotes: 2
Reputation: 1321
try this:
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String itemString=listView.getSelectedItem().toString();
}
});
Upvotes: 0
Reputation: 2690
Set OnItemClickListener on listview. See on below.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String itemString=listView.getSelectedItem().toString();
}
});
Enjoy!!!...
Upvotes: 1