2013-04-19 81 views
0

我有一個對象:如何在選擇微調器時更改對象的值?

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在不同的方法中定義的內部類中」

任何人都可以幫我嗎?


回答

0

變化

PanggilOlahraga olahraga = PanggilOlahragaList.get(position); 

final PanggilOlahraga olahraga = PanggilOlahragaList.get(position); 

,你就可以提到它的匿名內部類。

+0

我試過了,但waktu的值仍然沒有改變... – ditaditaa

+0

或者,我如何訪問_position_變量_onItemSelected()_? – ditaditaa

相關問題