Detect Long Click on Two Item List View
<p>Let me start by saying I am new to Android development but have a strong background in C#, VB.</p>

<p>I have read a ton of posts on similar issues and tried the solutions but it never seems to work. I am certain it is something I am doing and it is based on my ignorance of the programming language.</p>

<p>So, I got some code for a ListAdapter to populate the Two Item List View. </p>

<pre><code>import java.util.ArrayList;
...


public class ListAdapter extends BaseAdapter {

private Activity activity;
  private ArrayList&lt;Integer&gt; image;
  private ArrayList&lt;String&gt; list1;
  private ArrayList&lt;String&gt; list2;
  private static LayoutInflater inflater=null;

  public ListAdapter(Activity a, ArrayList&lt;Integer&gt; image, ArrayList&lt;String&gt; list1, ArrayList&lt;String&gt; list2) {
      this.activity = a;         
      this.image = image;
      this.list1 = list1;
      this.list2 = list2;
      ListAdapter.inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);      
  }

  public int getCount() {
    return image.size();        
  }

  public Object getItem(int position) {
      return position;
  }

  public long getItemId(int position) {
      return position;
  }

  public static class ViewHolder{
      public TextView text1;
      public TextView text2;
      public ImageView image;
  }

  public View getView(int position, View convertView, ViewGroup parent) {
      View vi=convertView;
      ViewHolder holder;
      if(convertView==null){

          vi = inflater.inflate(R.layout.grid_list_layout, null);

          holder=new ViewHolder();
          holder.text1=(TextView)vi.findViewById(R.id.item1);
          holder.text2=(TextView)vi.findViewById(R.id.item2);
          holder.image = (ImageView)vi.findViewById(R.id.icon);

          vi.setTag(holder);
      }
      else
          holder=(ViewHolder)vi.getTag();

          holder.text1.setText(this.list1.get(position));
          holder.text2.setText(this.list2.get(position));
          holder.image.setImageResource(this.image.get(position));

          return vi;
  }
</code></pre>

<p>}</p>

<p>I have modified the above to use ArrayList instead of Array in the original article. It works fine. What I want to do is detect the long click and prompt the user to delete or not.</p>

<p>The main.xml has this partial code which is the list view</p>

<pre><code>&lt;ListView
    android:id="@+id/lvResult"
    android:layout_width="fill_parent"
    android:layout_height="296dp"
    android:paddingLeft="10px"
    android:paddingRight="10px" &gt;
&lt;/ListView&gt;
</code></pre>

<p>There is another grid_list_layout.xml file which contains</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" &gt;

&lt;ImageView
    android:id="@+id/icon"
    android:layout_width="72px"
    android:layout_height="wrap_content"
    android:layout_marginTop="5px" /&gt;

&lt;TwoLineListItem
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/twolinelist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:onClick="onClick"
    android:orientation="vertical"
    android:paddingBottom="5px"
    android:paddingTop="5px" &gt;

    &lt;TextView
        android:id="@+id/item1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

    &lt;TextView
        android:id="@+id/item2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="30px"
        android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
&lt;/TwoLineListItem&gt;
</code></pre>

<p></p>

<p>In the main activity it is instantiated(?) with</p>

<pre><code>ListView lv = (ListView) findViewById(R.id.lvResult);
//listAdapter is declared further up
listAdapter = new ListAdapter(HomesterActivity.this, arrIcon, arrSSID, arrMAC);
    lv.setAdapter(listAdapter);
</code></pre>

<p>So, what I would like to know is how do I intercept a long click? Where do I put the various bits? i.e. there must be something in the XML file, but which one? I have tried </p>

<pre><code>lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onListItemClick(ListView l, View v, int position,long id)
        {
            //super.onListItemClick( l, v, position, id);
            Toast.makeText(this, position, Toast.LENGTH_LONG).show();
        }
    }
</code></pre>

<p>and various versions, but nothing seems to please the compiler!</p>

<p>If you have time and feel so inclined I would appreciate some education so I can get my mind around it.</p>
