Java 在每个项目上使用两个可单击的按钮实现一个不可单击的ListView

Java 在每个项目上使用两个可单击的按钮实现一个不可单击的ListView,java,android,xml,listview,button,Java,Android,Xml,Listview,Button,我试图用两个按钮创建一个列表视图,当我点击任何按钮时,我需要知道列表的位置,但我需要使项目变得不可点击 有人能帮我吗 这是my item.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android

我试图用两个按钮创建一个列表视图,当我点击任何按钮时,我需要知道列表的位置,但我需要使项目变得不可点击

有人能帮我吗

这是my item.xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/Clear">

    <ImageView
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/Clear"
        android:layout_centerHorizontal="true"
        android:id="@+id/imgProducte"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"/>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/nomPreuQuantitat"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_below="@id/imgProducte"
        android:layout_marginBottom="3dp"
        android:layout_centerHorizontal="true"
        android:textSize="18sp"
        android:gravity="center"
        android:text="test1"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"/>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/nomPreuQuantitat"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginBottom="3dp"
        android:textSize="16sp"
        android:layout_centerHorizontal="true"
        android:id="@+id/descripcio"
        android:gravity="center"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_below="@id/descripcio">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="10dp"
            android:id="@+id/btn_menys"
            android:background="@drawable/b_minus"
            android:focusable="false"
            android:clickable="false"
            android:focusableInTouchMode="false"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginBottom="10dp"
            android:id="@+id/quantitat"
            android:background="@drawable/b_buit"
            android:gravity="center"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:clickable="false"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="10dp"
            android:onClick=""
            android:id="@+id/btn_mes"
            android:background="@drawable/b_plus"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:clickable="false"/>
    </LinearLayout>
</RelativeLayout>

我的java类是:

lstProductes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getApplicationContext(),""+view.isSelected(),Toast.LENGTH_SHORT).show();
            try {
                final Button botoAfegir = (Button) findViewById(R.id.btn_mes);
                final Button botoRestar = (Button) findViewById(R.id.btn_menys);
                final String concepte = arraiProductes.get(position).getName();

                botoAfegir.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(), "Afegir " + concepte, Toast.LENGTH_SHORT).show();
                    }
                });
                botoRestar.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(), "Restar " + concepte, Toast.LENGTH_SHORT).show();
                    }
                });
            } catch (Exception exc) {
                Toast.makeText(getApplicationContext(), exc.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    });
lstproducts.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
Toast.makeText(getApplicationContext(),“”+view.isSelected(),Toast.LENGTH\u SHORT.show();
试一试{
最终按钮botoAfegir=(按钮)findViewById(R.id.btn_mes);
最终按钮botoRestar=(按钮)findViewById(R.id.btn_menys);
最后一个字符串concept=arraiproducts.get(position.getName();
botoAfegir.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(getApplicationContext(),“Afegir”+概念,Toast.LENGTH\u SHORT.show();
}
});
botoRestar.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(getApplicationContext(),“Restar”+concept,Toast.LENGTH_SHORT).show();
}
});
}捕获(异常exc){
Toast.makeText(getApplicationContext(),exc.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
制作您在适配器的getView中提到的布局(适配器的getView中的convertView),单击布局中的按钮时,将其设置为可单击为false


并在适配器的getView中提到单击侦听器

您能否详细说明一下,但我需要使该项变得不可访问!在你的客户的
getView
中定义按钮点击监听器如果你的项目不应该是可点击的,为什么你会有一个onItemClickListener?我实现onItemClickListener是为了知道项目的位置,但我想你是对的,我将定义ClickListener,知道所选行的任何想法吗?非常感谢!!在getView上定义按钮之后,问题就解决了!!