Android 按钮不可点击列表视图

Android 按钮不可点击列表视图,android,listview,custom-adapter,Android,Listview,Custom Adapter,我有一个列表视图,每行有一个按钮。问题是,我可以单击我的listView项目,然后发生了一些事情,但我的按钮不起作用,什么也没有发生。我读过一些关于这个解决方案的书,但没有一本对我有帮助 这是我的列表\u row.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientatio

我有一个列表视图,每行有一个按钮。问题是,我可以单击我的listView项目,然后发生了一些事情,但我的按钮不起作用,什么也没有发生。我读过一些关于这个解决方案的书,但没有一本对我有帮助

这是我的列表\u row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:descendantFocusability="blocksDescendants"
>
<TextView
    android:id="@+id/text_branche_cours"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="English"
    />

<TextView
    android:id="@+id/text_trait"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" - "
    />
<TextView
    android:id="@+id/text_designation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Reading"
    android:layout_marginRight="150dp"
    />
<Button
    android:id="@+id/bAjouterJalon"
    android:layout_width="58dp"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_action_add_jalon"
谢谢你的帮助


@编辑-我的列表视图现在不可点击

您正在使按钮可聚焦&聚焦于touch false,这样它就不会检测到按钮上的触摸标签,请从xml中的按钮标签中删除以下两行:

       android:focusable="false"
       android:focusableInTouchMode="false"
例如:

     <Button
       android:id="@+id/bAjouterJalon"
       android:layout_width="58dp"
       android:layout_height="wrap_content"
       android:background="@drawable/ic_action_add_jalon"
       />
列表项xml:

   <?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/item_root"
        android:descendantFocusability="blocksDescendants"
        android:orientation="horizontal"
        android:padding="16dp">

        <TextView
            android:id="@+id/text_branche_cours"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="English" />

        <TextView
            android:id="@+id/text_trait"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text=" - " />

        <TextView
            android:id="@+id/text_designation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="150dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Reading" />

        <Button
            android:id="@+id/bAjouterJalon"
            android:layout_width="58dp"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_action_add_jalon" />
    </LinearLayout>

在您的列表中_itemxml put
android:genderantfocusability=“blocksDescendants

在线性布局中。

您是否尝试过在getView上而不是在bindView中处理按钮单击?不,我怎么能这样做?是的,它工作了,但现在我的listView不可单击,但我的按钮工作了。您希望两者都可以单击?(列表项和按钮)是的,在每一行中我都有一些文本和按钮,我想根据我点击的内容同时点击这两个按钮并执行相应的操作是的,为不同的操作添加了相应的更改。还有我的listView的代码。setOnItemClickListener必须转到你给我的空方法吗?
public class CustomAdapter extends SimpleCursorAdapter {
                private Context mContext;
                private Context appContext;
                private int layout;
                private Cursor cr;
                private final LayoutInflater inflater;

                public CustomAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
                    super(context, layout, c, from, to);
                    this.layout = layout;
                    this.mContext = context;
                    this.inflater = LayoutInflater.from(context);
                    this.cr = c;
                }

                @Override
                public View newView(Context context, Cursor cursor, ViewGroup parent) {
                    return inflater.inflate(layout, null);
                }

                @Override
                public void bindView(View view, final Context context, final Cursor cursor) {
                    super.bindView(view, context, cursor);


                    final Button ajouter = (Button)view.findViewById(R.id.bAjouterJalon);

                    final LinearLayout root_view = (LinearLayout)view.findViewById(R.id.item_root);

                    root_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          // List item Click detected

                        }
                    });


                    ajouter.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent retour = new Intent(mContext,OngletJalonsNotes.class);
                            mContext.startActivity(retour);

                        }
                    });
                }
            }
   <?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/item_root"
        android:descendantFocusability="blocksDescendants"
        android:orientation="horizontal"
        android:padding="16dp">

        <TextView
            android:id="@+id/text_branche_cours"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="English" />

        <TextView
            android:id="@+id/text_trait"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text=" - " />

        <TextView
            android:id="@+id/text_designation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="150dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Reading" />

        <Button
            android:id="@+id/bAjouterJalon"
            android:layout_width="58dp"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_action_add_jalon" />
    </LinearLayout>