下午好,findViewByIdAndroid的電話從適配器自定義類
所以我對此有一個爲每個行的複選框的項目的自定義適配器的自定義的ListView。在我的getView中,我爲我的複選框實現了setOnCheckedChangeListener和onCheckedChanged處理程序。現在
,問題是:
每當我選中/取消選中列表中的項目之一,我想更新我想(假設每個項目的值的外部的TextView有關聯,使得價格我想在名單下面顯示總價格)。
我該如何從getView的適配器到達「外部」視圖?我還有其他什麼解決方法?
我離開這裏我的代碼一些部分我的自定義適配器的getView功能:
CheckBox name = (CheckBox) view.findViewById(R.id.product);
name.setText(content[i][0]);
final View v = view;
final int position = i;
name.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton group, boolean isChecked) {
setCheckedItem(position);
EditText quantity = (EditText) v.findViewById(R.id.product_quantity);
content[position][3] = quantity.getText().toString();
Iterator<String> it = getCheckedItems().values().iterator();
Double total = 0.0;
for (int i=0;i<getCheckedItems().size();i++){
Integer quantity_p = Integer.parseInt(getItem(position)[3]);
Double price = Double.parseDouble(getItem(position)[2]);
total += quantity_p*price;
}
TextView total_price = (TextView) findViewById(R.id.total_products_price);
total_price.setText(total.toString());
}
});
注意最後兩行:我知道我不能調用findViewById,但我不知道是什麼現在要做。任何建議都會很好,謝謝。
可以把你的類代碼和xml文件放在這裏嗎? – 2014-11-04 11:55:30
將您的適配器類放入活動類中。 – 2014-11-04 11:58:51