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;
}