2013-06-02 73 views
0

如何在列表加載後從此列表視圖中獲得複選框(選中/未選中)的狀態?如何從此列表視圖中獲取複選框的狀態(選中/取消選中)?

我知道如何通過重寫適配器的getview方法來檢查列表何時加載,但事實並非如此。

我需要的是在列表加載完成後獲得狀態,並且用戶選中/取消選中列表中的項目並從菜單中點擊備份或刪除按鈕。

enter image description here

謝謝。

+0

http://stackoverflow.com/questions/16685366/customised-listview-using-arrayadapter-class-in-android/16686623#16686623。檢查這個鏈接 – Raghunandan

回答

0

你的問題太模糊.. 只有我可以用信息的你給量回答的事情是把在你的適配器:

chkBox = (CheckBox) findViewById(R.id.chkBox); 

    chkIos.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
       //is chkBox checked? 
     if (((CheckBox) v).isChecked()) { 
      Toast.makeText(MyAndroidAppActivity.this, 
       "result:", Toast.LENGTH_LONG).show(); 
     } 

     } 
    }); 
0

你可以嘗試這樣的

@Override 
     public View getView(int position, View convertView, ViewGroup parent) { 

     ViewHolder holder = null; 
     Log.v("ConvertView", String.valueOf(position)); 

     if (convertView == null) { 
     LayoutInflater vi = (LayoutInflater)getSystemService(
     Context.LAYOUT_INFLATER_SERVICE); 
     convertView = vi.inflate(R.layout.country_info, null); 

     holder = new ViewHolder(); 
     holder.code = (TextView) convertView.findViewById(R.id.code); 
     holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1); 
     convertView.setTag(holder); 

     holder.name.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      CheckBox cb = (CheckBox) v ; 
      Country country = (Country) cb.getTag(); 
      Toast.makeText(getApplicationContext(), "Clicked on Checkbox: " + cb.getText() + 
      " is " + cb.isChecked(),Toast.LENGTH_LONG).show(); 
      country.setSelected(cb.isChecked()); 
     } 
     }); 
     } 
     else { 
     holder = (ViewHolder) convertView.getTag(); 
     } 

     Country country = countryList.get(position); 
     holder.code.setText(" (" + country.getCode() + ")"); 
     holder.name.setText(country.getName()); 
     holder.name.setChecked(country.isSelected()); 
     holder.name.setTag(country); 

     return convertView; 

     } 
相關問題