0
我的列表行還包含一個複選框,其中還有一些其他視圖。當我選中或取消選中複選框時,其關聯的操作偵聽器不會被觸發。以下是getView()的代碼片段。請看看並提供解決方案。複選框onclicklistener不能在列表行中工作android
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;
}
但是,如果我不使用onClickListener被炒魷魚Activity而不是ListActivity。 –
酷對不起,即使onclicklistener工程只是檢查出來.. –
但在我的情況下,它不工作 –