2012-06-19 25 views
-1

iam正在開發應用程序備份應用程序,我想這樣做只會備份通過複選框選擇的應用程序。我已經實現了複選框的列表,但當我檢查每行第9行前後,它也成爲檢查:S每隔9行就會被檢查

PS。我也明白,如果有人可以幫助我在whay的唯一我怎麼能做出這樣的應用程序的備份也工作:)

(這僅僅是一個完整的Java文件的PICE)

private static class AppViewHolder { 
    TextView top_view; 
    TextView bottom_view; 
    ImageView icon; 
    CheckBox check_mark; 
    //@SuppressWarnings("unused") 
} 

private class TableView extends ArrayAdapter<ApplicationInfo> { 

    private TableView() { 
     super(main.this, R.layout.tablerow_02, mAppList); 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     AppViewHolder holder; 
     ApplicationInfo info = mAppList.get(position); 

     if(convertView == null) { 
      LayoutInflater inflater = getLayoutInflater(); 
      convertView = inflater.inflate(R.layout.tablerow_02, parent, false); 

      holder = new AppViewHolder(); 
      holder.top_view = (TextView)convertView.findViewById(R.id.top_view); 
      holder.bottom_view = (TextView)convertView.findViewById(R.id.bottom_view); 

      holder.check_mark = (CheckBox)convertView.findViewById(R.id.checkBox1); 


      holder.icon = (ImageView)convertView.findViewById(R.id.row_image); 
      holder.icon.setMaxHeight(40); 
      convertView.setTag(holder); 

     } else { 
      holder = (AppViewHolder) convertView.getTag(); 
     } 

     holder.check_mark.setOnCheckedChangeListener(new OnCheckedChangeListener(){ 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
      { 
       if (isChecked) 
       { 
        Toast.makeText(getApplicationContext(), "#" + position + " is checked", Toast.LENGTH_LONG).show(); 
       } 
       else{ 
        Toast.makeText(getApplicationContext(), "#" + position + " is unchecked", Toast.LENGTH_LONG).show(); 
       } 

      } 
     }); 

     holder.top_view.setText(info.loadLabel(getPackageManager())); 
     holder.bottom_view.setText(info.packageName); 

     //this should not throw the exception 
     try { 
      holder.icon.setImageDrawable(mPackMag.getApplicationIcon(info.packageName)); 
     } catch (NameNotFoundException e) { 
      holder.icon.setImageResource(R.drawable.ic_launcher); 
     } 

     return convertView; 
    } 

} 

回答

3

因爲你沒有正確回收視圖。您應該保留一組布爾值,列表中的每個項目都有一個布爾值。然後在getView中,您需要根據該布爾值列表中的值,根據holder.check_mark調用setChecked