Search code examples
androidmysqlsqllistviewonitemclick

get string value from item clicked in a listView


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


Solution

  • 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