title: How to get item value in a listview in android?
body: <p>I have referenced to a tutorial and I have created a custom list view in fragment, but I am unable to get the position or value of any item on item click of list view. I want to show a toast containing the position of the item. I don't know how to implement that.</p>
  
  <p>CustomListAdapter.java</p>
  
  <pre><code>public class CustomListAdapter extends BaseAdapter{
  
      private ArrayList&lt;MyActivityAdapterItem&gt; listData;
      private Context context;
  
      //private LayoutInflater layoutInflater;
  
      public CustomListAdapter(Context context, ArrayList&lt;MyActivityAdapterItem&gt; listData) {
          this.listData = listData;
          this.context = context;
  
      }
  
      @Override
      public int getCount() {
          return listData.size();
      }
  
      @Override
      public Object getItem(int position) {
          return listData.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          //ViewHolder holder;
          if (convertView == null) {
              LayoutInflater mInflater = (LayoutInflater)
                      context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
              convertView = mInflater.inflate(R.layout.list_row_layout, null);
             // holder = new ViewHolder();
  
              //convertView.setTag(holder);
          } 
          TextView headingView = (TextView) convertView.findViewById(R.id.title);
          TextView placeView = (TextView) convertView.findViewById(R.id.place);
           TextView reportedDateView = (TextView) convertView.findViewById(R.id.date);
  
          headingView.setText(listData.get(position).getHeading());
          placeView.setText("At, " + listData.get(position).getPlace());
          reportedDateView.setText(listData.get(position).getDate());
  
          return convertView;
      }
  
  }
  </code></pre>
  
  <p>FindPeopleFragment.java</p>
  
  <pre><code>public class FindPeopleFragment extends Fragment implements OnClickListener {
      AlertDialog.Builder builder ;
      ListView lv1;
      ImageButton delall;
      CharSequence options[] = new CharSequence[] {"Delete"};
      ArrayList details;
      CustomListAdapter ad1;
      String msg="abc";
      public FindPeopleFragment(){}
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
          delall=(ImageButton) rootView.findViewById(R.id.deleteall);
          details = getListData();
          lv1 = (ListView) rootView.findViewById(R.id.activitylist);
          ad1=new CustomListAdapter(getActivity(), details);
          lv1.setAdapter(ad1);
          builder= new AlertDialog.Builder(getActivity());
          delall.setOnClickListener(this);
         lv1.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                  long arg3) {
              // TODO Auto-generated method stub
  
              //Toast.makeText(getActivity(), , Toast.LENGTH_LONG).show();
              /*Bundle args = new Bundle();
              args.putString(MyActivitiesFragment.MSG, msg);
              MyActivitiesFragment f1=new MyActivitiesFragment();
              f1.setArguments(args);
              MainActivity.fm.beginTransaction().replace(R.id.frame_container,f1).commit();*/
          }
      });
  return rootView;
  }
  </code></pre>