我有一个对象:
PanggilOlahraga( nama, met, waktu, kalori )
我有一个微调器,其中包含“waktu”值。
选择旋转器值时,我想更改“ waktu”值。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.d("ConvertView", String.valueOf(position));
PanggilOlahraga olahraga = PanggilOlahragaList.get(position);
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.olahragainet_info, null);
holder = new ViewHolder();
holder.nama = (TextView) convertView.findViewById(R.id.tvNamaOlgaInet);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.cbOlga);
holder.sp = (Spinner) convertView.findViewById(R.id.spWaktu);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
getApplicationContext(), R.layout.my_spinner_textview, items1);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.sp.setAdapter(adapter1);
holder.sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Object item = parent.getItemAtPosition(pos);
txtWaktu = item.toString();
double dwaktu = Double.parseDouble(txtWaktu);
olahraga.setWaktu(dwaktu);
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
convertView.setTag(holder);
// ACTION CLICKED ON CHECK BOX
holder.checkbox.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
PanggilOlahraga olahraga = (PanggilOlahraga) cb.getTag();
olahraga.setSelected(cb.isChecked());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
kalori = olahraga.getMet() * olahraga.getWaktu() / 60.0 * berat;
holder.nama.setText(olahraga.getNama());
holder.checkbox.setChecked(olahraga.isSelected());
holder.checkbox.setTag(olahraga);
olahraga.setKalori(kalori);
return convertView;
}
但是,我在olahraga.setWaktu(dwaktu)中有一个错误。
它说“不能在以不同方法定义的内部类中引用非变量 olahraga”
任何人都可以帮助我吗?