Android ListView中的TextView在整行上不可选

Android ListView中的TextView在整行上不可选,android,listview,android-listview,clickable,Android,Listview,Android Listview,Clickable,我的XML是 活动单元布局 <?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

我的XML是

活动单元布局

<?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>
还有我的定制适配器

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

将android:clickable=“false”添加到文本视图中。这将使触摸事件进入底层行。

android:clickable=“false”
添加到文本视图。这将使触摸事件进入您的底层行。

listview项的根元素具有
android:layout\u width=“wrap\u content”
将其更改为
match\u parent
(在您的CustomAdapter xml中)

listview项的根元素具有
android:layout\u width=“wrap\u content”
将其更改为
match\u parent
(在您的CustomAdapter xml中)

显然,我必须更改我的activity.xml文件的
android:layout\u width
根元素


显然,我必须更改activity.xml文件的
android:layout\u width
根元素


这对我来说是个好办法。

你试过将可见性设置为“消失”吗


您是否尝试将可见性设置为“已消失”



请发布您的点击。特别是在您将其添加到视图的位置。@MLProgrammer CiM EDITEd.try
android:focusableInTouchMode=“false”
android:clickable=“false”
到文本视图中您在哪里提到过文本视图的onclicklisteners?@SagarPilkhwal仍然没有。请发布您的单击侦听器。特别是您将其添加到视图中的位置。@MLProgrammer CiM EDITEd.try
android:focusableInTouchMode=“false”
android:clickable=“false”
到文本视图中,您在哪里提到了文本视图的onclicklisteners?@SagarPilkhwal仍然没有什么。您是否将其添加到两个文本视图中?是否将其添加到两个文本视图中?那么它大约是整个列表视图的大小。我认为这是因为行的宽度:(然后是整个listview的大小。我认为这是因为行的宽度:(
        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
            }
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;
}
<TextView
    android:id="@+id/categoryIDText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone">
</TextView>