1

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

Shoogarh
  • 9
  • 1
  • 6

3 Answers3

2

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
Mr. Concolato
  • 2,224
  • 5
  • 24
  • 44
  • Thank you.. your answer have been So helpful.. each item contains more than one string values.. now What I want is to retrieve the values of the clicked item and store Them in string variables – Shoogarh Dec 13 '14 at 19:28
  • Without your code, It is hard to determine what you mean. Also, if you think people have been somewhat helpful, give them a thumbs up ;) – Mr. Concolato Dec 14 '14 at 11:59
  • I cant really give thumbs up because i cant see the options here on the mobile app.. but all the answers has helped me.. – Shoogarh Dec 14 '14 at 19:13
1

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!!!...

Ganesh Katikar
  • 2,620
  • 1
  • 26
  • 28
0

try this:

listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                String itemString=listView.getSelectedItem().toString();
            }

        });
balaji koduri
  • 1,321
  • 9
  • 25
  • Thank you.. your answer have been So helpful.. each item contains more than one string values.. now What I want is to retrieve the values of the clicked item and store Them in string variables – Shoogarh Dec 13 '14 at 19:27