0

My XMLs are

activity_layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >

<ListView
    android:id="@+id/categoriesList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</ListView>

</LinearLayout>

And the customAdaptor

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >

<TextView
    android:id="@+id/categoryIDText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="invisible">
</TextView>

<TextView
    android:id="@+id/categoryName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="20px" >
</TextView>

</LinearLayout>

So, within each row, I have two textViews. One is hidden, and other is visible.

Now, when I click on any row, the only clickable area is the one where TextView's string ends.

i.e. if my TextView categoryName has one element set as Hello then the listview's row looks like

Hello [BLANK SPACE HERE]

And when i touch the are where it is BLANK SPACE, it does not respond to the touch. But when I touch the area, where it is Hello, then it responds.

What should I do to make the entire row clickable?

Thanks

EDIT

        listView.setAdapter(new CategoryAdapter(this, categories));
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text
            }

And my custom adaptor

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView = inflater.inflate(R.layout.list_view_category, parent, false);
    TextView textViewID = (TextView) rowView.findViewById(R.id.categoryIDText);
    TextView textViewName = (TextView) rowView.findViewById(R.id.categoryName);
    textViewID.setText(""+data.get(position).getId());
    textViewName.setText(data.get(position).getName()); 
    return rowView;
}
Kraken
  • 23,393
  • 37
  • 102
  • 162

4 Answers4

3

Apparently I had to change the android:layout_width root element of my activity.xml file.

That did the trick for me.

Kraken
  • 23,393
  • 37
  • 102
  • 162
1

The root element of your listview item has android:layout_width="wrap_content" change it to match_parent (in your customAdaptor xml)

yildirimyigit
  • 3,013
  • 4
  • 25
  • 35
0

Add android:clickable="false" to the TextView. This will make the touch event fall through to your underlying row.

Dan Harms
  • 4,725
  • 2
  • 18
  • 28
0

Have you tried setting the visibility to "gone"?

<TextView
    android:id="@+id/categoryIDText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone">
</TextView>
arlistan
  • 731
  • 9
  • 20