Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of a Listview item which is clicked in android?

I have this below code access the ListView item value into string and display it in alert?

ListView shot = getListView();
shot.setOnItemClickListener(this);

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

    String S = arg1.getContext().toString();
    AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

    // set the message to display
    alertbox.setMessage(S).show();    
}
like image 203
Srikanth Naidu Avatar asked Jun 07 '10 09:06

Srikanth Naidu


1 Answers

This gives you the exact value of the item clicked. Check the log

ListView shot = getListView();
shot.setOnItemClickListener(this);

public void onItemClick(AdapterView<?> parent, View view, int position,long id) {

    String val =(String) parent.getItemAtPosition(position);
    System.out.println("Value is "+val); 
}
like image 169
Droido Avatar answered Sep 19 '22 07:09

Droido