Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “Listview侦听器不适用于”复选框?_Android_Listview_Checkbox - Fatal编程技术网

Android “Listview侦听器不适用于”复选框?

Android “Listview侦听器不适用于”复选框?,android,listview,checkbox,Android,Listview,Checkbox,我有一个列表视图,其元素如下所示,包含一个复选框 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="@color/white" android:orientation="vertical" and

我有一个列表视图,其元素如下所示,包含一个复选框

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:layout_height="wrap_content">

<RelativeLayout
    android:layout_width="match_parent"
    android:minHeight="64dp"
    android:layout_marginRight="8dp"
    android:layout_marginLeft="8dp"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageViewVoucherIcon"
        android:layout_width="50dp"
        android:layout_centerVertical="true"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textViewVoucherText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:layout_toLeftOf="@+id/checkboxVoucherClick"
        android:layout_centerVertical="true"
        android:layout_marginLeft="8dp"
        android:textColor="@color/text"
        android:text="sas"
        android:layout_toRightOf="@+id/imageViewVoucherIcon" />

    <CheckBox
        android:id="@+id/checkboxVoucherClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/seperator" />
</LinearLayout>

这是我的onitem click侦听器

 lvVoucher.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)  {
           CheckBox cb=(CheckBox)view.findViewById(R.id.checkboxVoucherClick);
            if(cb.isChecked())
            {
                Log.e("check","true");
            }else{
                Log.e("check","false");
            }
        }
    });
lvconcedure.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
复选框cb=(复选框)view.findViewById(R.id.checkboxVoucherClick);
if(cb.isChecked())
{
Log.e(“检查”、“真实”);
}否则{
Log.e(“检查”、“假”);
}
}
});

但是它不会返回任何内容。

将焦点移到布局中的复选框,然后它就会工作

像这样:

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:focusable="false"
        android:focusableInTouchMode="false"/>


否则,您必须在适配器本身中编写该侦听器。

将焦点移到布局中的复选框,然后它将工作

像这样:

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:focusable="false"
        android:focusableInTouchMode="false"/>


否则,您必须在适配器本身中编写该侦听器。

将焦点移到布局中的复选框,然后它将工作

像这样:

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:focusable="false"
        android:focusableInTouchMode="false"/>


否则,您必须在适配器本身中编写该侦听器。

将焦点移到布局中的复选框,然后它将工作

像这样:

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:focusable="false"
        android:focusableInTouchMode="false"/>


否则,您必须在适配器本身中编写侦听器。

我也遇到了同样的问题,这对我来说很有效

为复选框设置以下属性:

      android:focusable="false"
      android:focusableInTouchMode="false"

我也有同样的问题,这对我来说很有用

为复选框设置以下属性:

      android:focusable="false"
      android:focusableInTouchMode="false"

我也有同样的问题,这对我来说很有用

为复选框设置以下属性:

      android:focusable="false"
      android:focusableInTouchMode="false"

我也有同样的问题,这对我来说很有用

为复选框设置以下属性:

      android:focusable="false"
      android:focusableInTouchMode="false"

您必须在xml父布局中添加新行-

android:descendantFocusability="blocksDescendants"
因此,您的更新视图如下所示-

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    android:layout_height="wrap_content">


它肯定会对您有用。

您必须在xml父布局中添加新行-

android:descendantFocusability="blocksDescendants"
因此,您的更新视图如下所示-

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    android:layout_height="wrap_content">


它肯定会对您有用。

您必须在xml父布局中添加新行-

android:descendantFocusability="blocksDescendants"
因此,您的更新视图如下所示-

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    android:layout_height="wrap_content">


它肯定会对您有用。

您必须在xml父布局中添加新行-

android:descendantFocusability="blocksDescendants"
因此,您的更新视图如下所示-

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    android:layout_height="wrap_content">


它肯定会为您工作。

getView中工作

 holder.checkbox.setOnClickListener( new View.OnClickListener() {  
 public void onClick(View v) {  
  CheckBox cb = (CheckBox) v ;  
  Toast.makeText(getApplicationContext(),
   "Clicked on Checkbox: " + cb.getText() +
   " is " + cb.isChecked(), 
   Toast.LENGTH_LONG).show();
 }  
});  

getView

 holder.checkbox.setOnClickListener( new View.OnClickListener() {  
 public void onClick(View v) {  
  CheckBox cb = (CheckBox) v ;  
  Toast.makeText(getApplicationContext(),
   "Clicked on Checkbox: " + cb.getText() +
   " is " + cb.isChecked(), 
   Toast.LENGTH_LONG).show();
 }  
});  

getView

 holder.checkbox.setOnClickListener( new View.OnClickListener() {  
 public void onClick(View v) {  
  CheckBox cb = (CheckBox) v ;  
  Toast.makeText(getApplicationContext(),
   "Clicked on Checkbox: " + cb.getText() +
   " is " + cb.isChecked(), 
   Toast.LENGTH_LONG).show();
 }  
});  

getView

 holder.checkbox.setOnClickListener( new View.OnClickListener() {  
 public void onClick(View v) {  
  CheckBox cb = (CheckBox) v ;  
  Toast.makeText(getApplicationContext(),
   "Clicked on Checkbox: " + cb.getText() +
   " is " + cb.isChecked(), 
   Toast.LENGTH_LONG).show();
 }  
});  

是否希望复选框和其他小部件执行不同的操作?或者只需要为复选框单击操作是否希望为复选框和其他小部件执行不同的操作?或者只需要为复选框单击操作是否希望为复选框和其他小部件执行不同的操作?或者只需要为复选框单击操作是否希望为复选框和其他小部件执行不同的操作?或者只需要单击复选框的“操作”