title: how to get listview selected item text when clicked on AlertDialog button
body: <p>I am developing a simple application in android. In this app i am having a listview, which shows the inbox sms. On click of any item of listview, one AlertDialog appears, that contains Ignore,Cancel, &amp; Fix buttons.(Please refer images for this).</p>
  
  <p>On click of "Fix" button of AlertDailog, I want to get the text of selected item of listview.</p>
  
  <p>using following code, I am getting the text in String 'str' is like this:- <strong>com.example.myapp.Items@412a7d08</strong>(In log as well as on toast).</p>
  
  <p>I want the normal text in the string 'str'. (i.e text of selected item in listview).
  OR in other words,
  I want the same text as listview item in String str.</p>
  
  <p>Can anybody help me to solve this issue ?</p>
  
  <p>This is the code i have written :</p>
  
  <pre><code>TextView tv_view_task;
  ListView lv_view_task;
  static String sms = "";
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_view_task);
      tv_view_task=(TextView) findViewById(R.id.tv_view_task);
      lv_view_task=(ListView) findViewById(R.id.lv_view_task);
  
      //List&lt;String&gt; msgList = getSms();
     MyAdapter adapter=new MyAdapter(this,getSms());
     lv_view_task.setAdapter(adapter);
  
     lv_view_task.setOnItemClickListener(new OnItemClickListener() {
  
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1,final int arg2,
              long arg3) {
          // TODO Auto-generated method stub
  
  
          AlertDialog.Builder alert=new AlertDialog.Builder(ViewTask.this);
          alert.setTitle("What you want to do ?");
          alert.setIcon(R.drawable.ic_launcher);
  
          alert.setPositiveButton("Fix",new OnClickListener() {
  
              public void onClick(DialogInterface dialog, int which) {
                  // TODO Auto-generated method stub
                  String str=lv_view_task.getItemAtPosition(arg2).toString();
                  Toast.makeText(getApplicationContext(), str,Toast.LENGTH_LONG).show();
  
  
              }
          });
          alert.setNegativeButton("Ignore",new OnClickListener() {
  
              public void onClick(DialogInterface dialog, int which) {
                  // TODO Auto-generated method stub
  
              }
          });
          alert.setNeutralButton("cancel",new OnClickListener() {
  
              public void onClick(DialogInterface dialog, int which) {
                  // TODO Auto-generated method stub
                  dialog.cancel();
              }
          });
          AlertDialog ale=alert.create();
          ale.show();
      }
  });
  }
  </code></pre>
  
  <p>My Adapter code is :</p>
  
  <pre><code>package com.example.myapp;
  
  import java.util.ArrayList;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  
  public class MyAdapter extends ArrayAdapter&lt;Items&gt; 
  {
  
   private final Context context;
   private final ArrayList&lt;Items&gt; itemsArrayList;
  public MyAdapter(Context context,ArrayList&lt;Items&gt;itemsArrayList) {
      super(context, R.layout.view_task_list_view,itemsArrayList);
      // TODO Auto-generated constructor stub
      this.context=context;
      this.itemsArrayList=itemsArrayList;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      LayoutInflater inflator=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View rowView=inflator.inflate(R.layout.view_task_list_view,parent,false);
      TextView label=(TextView) rowView.findViewById(R.id.label);
      //TextView view_task_priority=(TextView) rowView.findViewById(R.id.view_task_tv_priority);
      label.setText(itemsArrayList.get(position).getTitle());
      //view_task_priority.setText(itemsArrayList.get(position).getPriority());
      return rowView;
  }
  
  }
  </code></pre>
  
  <p>XML for custom listview...:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"&gt;
  
   &lt;TextView
      android:id="@+id/label"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="30px"
      android:paddingLeft="5dp"
      android:text="title"
      android:textColor="@color/Black"&gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Images : 1) ListView:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/7mbb6.png" alt="enter image description here"></p>
  
  <p><strong>2) AlertDialog : Here user clicks on "Fix" to get selected item text of listView.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/Atc52.png" alt="enter image description here"></p>