Note that there are some explanatory texts on larger screens.

plurals
  1. POListView element not clickable
    text
    copied!<p>I have a ListView with SimpleCursorAdapter. The layout was using a LinearLayout, but when reading manuals about memory consumption for complex (nested) layouts, I switched to RelativeLayout instead and I've managed to setup the layout exactly as I want.</p> <p>Now, there's one quirk. In the emulator, I cannot click the list items. It seems as if the elements are one big "no button". However, if I use the emulator arrows and select the listview element (highlights it) and click the button, it works fine.</p> <p>Why can't I "click" the listview items since I switched to RelativeLayout?</p> <p>Here's the XML:</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/locationName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Junk text" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:id="@+id/numStores" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/locationName" android:text="Junk text #1: 117" android:textSize="10dp" /&gt; &lt;TextView android:id="@+id/numItems" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/numStores" android:text="Junk text #2: 42" android:textSize="10dp" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I even tried <code>android:clickable="true"</code> for RelativeLayout, to no avail.</p> <p><strong>EDIT</strong> Code for onClick is as follows:</p> <pre><code>listItems.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { int countyID = cursor.getInt(cursor.getColumnIndex(LocationDB.C_ID)); int numItems = cursor.getInt(cursor.getColumnIndex(LocationDB.C_NUM_ITEMS)); int numStores = cursor.getInt(cursor.getColumnIndex(LocationDB.C_NUM_STORES)); String countyName = cursor.getString(cursor.getColumnIndex(LocationDB.C_NAME)); String foo = String.format(TAG + "Clicked ID #%d (%s), stores = %d, items = %d", countyID, countyName, numStores, numItems); Log.i(LOG_TAG, foo); // Show the item in a new activity Intent apan = new Intent(avBase, Browser.class); apan.putExtra("countyID", countyID); startActivity(apan); } }); </code></pre> <p><strong>EDIT 2</strong></p> <p>The code is now tested on my phone, and I get the same error; can't click the items when using RelativeLayout.</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