views:

51

answers:

2

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();    
}
A: 

maybe this example will help you

  lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
          Toast.LENGTH_SHORT).show();
    }
  });

http://developer.android.com/intl/zh-TW/resources/tutorials/views/hello-listview.html

zed_0xff
A: 

Maybe you can try this

String data = (String)shot.getItemAtPosition(arg2);
AlertDialog.Builder adb = new AlertDialog.Builder(arg1.getContext());              
adb.setMessage(data).show();
Uday