Android-Listview-McClickListener无法重新编码复选框选中事件
我最近开始在安卓上工作。我有一个listview,listview的行包含textview和checkbox。我正在活动程序中使用McClickListener来检查事件。我能进入奥涅斯特。但是在这里面,我不能得到checked事件,我已经尝试了很多,但是我的程序不能重新编码checkbox checked事件。请帮忙。下面是我的代码- 列表视图的行-Android-Listview-McClickListener无法重新编码复选框选中事件,android,android-listview,Android,Android Listview,我最近开始在安卓上工作。我有一个listview,listview的行包含textview和checkbox。我正在活动程序中使用McClickListener来检查事件。我能进入奥涅斯特。但是在这里面,我不能得到checked事件,我已经尝试了很多,但是我的程序不能重新编码checkbox checked事件。请帮忙。下面是我的代码- 列表视图的行- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/white" >
<TextView
android:id="@+id/tvShapeDesc"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:textColor="@android:color/black" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginRight="35dp"
android:background="@drawable/unchecked"
android:clickable="false"
android:focusable="false"
android:text="No"
android:visibility="visible"/>
</RelativeLayout>
下面是我的听众-
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg)
{
Toast.makeText(getApplicationContext(),
"Click ListItem Number " + position, Toast.LENGTH_LONG).show();
// CheckBox cbSelection = (CheckBox) view.getTag(position);
final CheckBox cbSelection = (CheckBox) view.findViewByI(R.id.checkBox1);
final Drawable checkedImage = view.getResources().getDrawable(R.drawable.checked);
final Drawable uncheckedImage = view.getResources().getDrawable(R.drawable.unchecked);
if((cbSelection).isChecked()){
Toast.makeText(getBaseContext(), "You checked " + position, Toast.LENGTH_SHORT).show();
selectedCounter++;
cbSelection.setVisibility(CheckBox.INVISIBLE);
cbSelection.setBackgroundDrawable(checkedImage);
cbSelection.setVisibility(CheckBox.VISIBLE);
} else {
Toast.makeText(getBaseContext(), "You unchecked " + position, Toast.LENGTH_SHORT).show();
selectedCounter--;
cbSelection.setBackgroundDrawable(uncheckedImage);
cbSelection.setVisibility(CheckBox.VISIBLE);
}
shapeStr = Integer.toString(selectedCounter) + " shapes(s) selected.";
shapeCountStr.setText(shapeStr);
}
lv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(适配器视图适配器、视图视图、整型位置、长参数)
{
Toast.makeText(getApplicationContext(),
“单击列表项目编号”+位置,Toast.LENGTH_LONG).show();
//复选框cbSelection=(复选框)view.getTag(位置);
最终复选框CBSLECTION=(复选框)view.findViewBy(R.id.checkBox1);
final Drawable checkedImage=view.getResources().getDrawable(R.Drawable.checked);
final Drawable uncheckedImage=view.getResources().getDrawable(R.Drawable.unchecked);
如果((cbSelection).isChecked()){
Toast.makeText(getBaseContext(),“youchecked”+位置,Toast.LENGTH\u SHORT.show();
选择计数器++;
cbSelection.setVisibility(复选框不可见);
CBS选举。挫折可追溯(检查图像);
cbSelection.setVisibility(CheckBox.VISIBLE);
}否则{
Toast.makeText(getBaseContext(),“youunchecked”+位置,Toast.LENGTH\u SHORT.show();
选择计数器--;
CBS选举。可退选(未勾选);
cbSelection.setVisibility(CheckBox.VISIBLE);
}
shapeStr=Integer.toString(selectedCounter)+“已选择形状。”;
shapeCountStr.setText(shapeStr);
}
程序没有进入内部-如果((cbSelection).isChecked()){…请帮助。非常感谢。尝试下面的代码
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
{
// checkbox ckecked
}
else
{
// checkbox un-ckecked
}
}
});
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
{
// checkbox ckecked
}
else
{
// checkbox un-ckecked
}
}
});