0

我的列表行还包含一个带有其他视图的复选框。当我选中或取消选中该复选框时,不会触发其关联的动作侦听器。以下是 getView() 的代码片段。请看一下并为我提供解决方案。

    public View getView(int position, View convertView, ViewGroup parent) {
        //ViewHolder holder;

        if (convertView == null) 
        {
            convertView = mInflater.inflate(R.layout.list_item, null);
            Log.i("adapter", "ADAPTER");
        }

        checkTax = (CheckBox) convertView.findViewById(R.id.check_tax);
        checkTax.setOnCheckedChangeListener(new OnCheckedChangeListener () {      
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)          {
                        Log.i("on click", "ON CLICK");
                if (isChecked) {
                    tvSelectTaxAccount.setVisibility(View.VISIBLE);
                    spinnerTaxAcc.setVisibility(View.VISIBLE);
                    tvTaxAmt.setVisibility(View.VISIBLE);
                    editTaxAmt.setVisibility(View.VISIBLE);
                    tvAmtAfterTax.setVisibility(View.VISIBLE);
                    amtAfterTax.setVisibility(View.VISIBLE);
                    tvAmt.setText("amount before tax");
                    Log.i("checked", "CHECKED");
                }
                else
                {
                    tvSelectTaxAccount.setVisibility(View.GONE);
                    spinnerTaxAcc.setVisibility(View.GONE);
                    tvTaxAmt.setVisibility(View.GONE);
                    editTaxAmt.setVisibility(View.GONE);
                    tvAmtAfterTax.setVisibility(View.GONE);
                    amtAfterTax.setVisibility(View.GONE);
                    tvAmt.setText("AMOUNT");
                    Log.i("unchecked", "UNCHECKED");
                }
            }

        });

        tvSelectTaxAccount = (TextView) convertView.findViewById(R.id.tv_select_tax_account);
        spinnerTaxAcc = (Spinner) convertView.findViewById(R.id.spinner_tax_acc);
        spinnerTaxAcc.setOnItemSelectedListener(selectSpinnerTaxAcc);

        tvTaxAmt = (TextView) convertView.findViewById(R.id.tv_tax_amt);
        editTaxAmt = (EditText) convertView.findViewById(R.id.edit_tax_amt);
        tvAmt = (TextView) convertView.findViewById(R.id.tv_amt);
        tvAmtAfterTax = (TextView) convertView.findViewById(R.id.tv_amt_after_tax);
        amtAfterTax = (TextView) convertView.findViewById(R.id.amt_after_tax);

    spinnerTaxAcc.setOnItemSelectedListener(selectSpinnerTaxAcc);

        tvSelectTaxAccount.setVisibility(View.GONE);
        spinnerTaxAcc.setVisibility(View.GONE);

        tvTaxAmt.setVisibility(View.GONE);
        editTaxAmt.setVisibility(View.GONE);
        tvAmtAfterTax.setVisibility(View.GONE);
        amtAfterTax.setVisibility(View.GONE);

        return convertView;
    }
4

1 回答 1

0

取消注释此行//checkTax.setOnClickListener(tax);并尝试使用 onclicklistener 或尝试使用

checkTax.setOnCheckedChangeListener(new OnCheckedChangeListener() {
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

   if(isChecked)
   {
    checkTax.setText("Check Box is checked");
   }
   else
   {
    checkTax.setText("not checked");
   }

});

我认为即使是 setOnCheckedChangeListener 也会在单击复选框时被触发

于 2012-10-07T18:17:36.793 回答