I have created a listview using the default ArrayAdapter. However, to select an item from the list I have to tap the item and not just the row. How can I change it in order to just click the row the item is in rather than the item itself?
Here is the code for my listview:
ListView mListView = (ListView) findViewById(android.R.id.list);
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.row, ans));
mListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View v, int i,
long l) {
Log.d(LOG_TAG,"Selected option"+i);
startActivity(intent);
finish();
}
});
Here is the xml for the listview:
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:divider="@drawable/list_divider"
android:dividerHeight="1dp" />
Here is the row.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/list_answers"
/>
Change your child views of the row to include
android:focusable="false". This will allow you to click the whole row. Right now, since each individual view thinks it can gain focus, they happen “on top” of the row.P.S. What we really need is the XML for the ROW of the ListView. Not the ListView itself. 🙂
Hope this helps,
FuzzicalLogic