Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid onItemClick silently fails
    text
    copied!<p>I'm displaying some sql data in a list via a ListAdapter. Everything works fine except when I try to set a click listener to each item in the list. Nothing happens when I click any of the items; no error messages, it just silently fails.</p> <pre><code>public class Notes extends ListActivity implements OnClickListener { private static final String TAG = "Notes"; private NotesData notes; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); notes = new NotesData(this); try { Cursor cursor = getNotes(); showNotes(cursor); /* set the cursor to the listadapter */ ListView ls = (ListView) findViewById(android.R.id.list); ls.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent,View v, int position,long id) { Toast.makeText(getApplicationContext(),"clicked", Toast.LENGTH_SHORT).show(); } }); } finally { notes.close(); } } </code></pre> <p>main.xml, containing the listview:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;Button android:id="@+id/new_note_button" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/new_note"/&gt; &lt;ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/empty" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/empty"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Is there something I'm missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload