title: display a dialog after long click on list view android
body: <p>in my application I will fetch data from a cursor and put it in a ListActivity.</p>
  <p>If a long click on a list item happens it should display a dialog.</p>
  <p><strong>Now I'll show you some code:</strong></p>
  <pre><code>final ListView selectRoom = (ListView) findViewById(android.R.id.list);
          selectRoom.setOnItemLongClickListener(new OnItemLongClickListener() {
  
              public boolean onItemLongClick(AdapterView&lt;?&gt; adapter, View view,
                      int position, long id) {
  
                  Cursor unitCursor = (Cursor) getListView().getItemAtPosition(
                          position);
                  int rid = unitCursor.getInt(0);
                  DBAccessor dba = new DBAccessor(getApplicationContext());
                  dba.alterUnitName(rid);
                  callAdapter();
                  final Dialog d = new Dialog(getApplicationContext());
                  d.setContentView(R.layout.settings);
                  d.setTitle(&quot;My Dialog&quot;);
                  d.show();
  
                  return true;
  </code></pre>
  <p>Here is the XML file with the List...</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot; &gt;
  
      &lt;Spinner
          android:id=&quot;@+id/spinnerRooms&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot; &gt;
      &lt;/Spinner&gt;
  
      &lt;ListView
          android:id=&quot;@android:id/android:list&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;wrap_content&quot; 
          android:layout_below=&quot;@id/spinnerRooms&quot;&gt;
      &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p>the XML file with the columns of cursor is...</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;horizontal&quot; &gt;
  
      &lt;TextView
          android:id=&quot;@+id/unitId&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot; 
          android:visibility=&quot;invisible&quot;/&gt;
  
      &lt;TextView
          android:id=&quot;@+id/unitName&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/unitRoomId&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot; 
          android:visibility=&quot;invisible&quot;/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <p>Thank you for some answers and have a nice day.</p>