2012-10-03 2 views
0

Android의 기본 메시지 응용 프로그램과 같은 알림 기능을 구현하고 있습니다. 이제 하나의 공통 체크 박스를 사용하여 목록의 모든 메시지를 선택하는 확인란을 추가하여 여러 메시지 삭제를 수행하고 있습니다. 그러나 CustomAdpter의 getview에있는 listview 체크 박스를 확인할 수 없습니다.모두 선택 및 선택 지우기 확인란

class customListAdpter extends BaseAdapter { 
    private Context ctx; 
    CheckBox checkBox; 
    TextView sender, message; 

    customListAdpter(Context context) { 
     this.ctx = context; 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return new NotifiCation().senderlist.size(); 
    } 

    @Override 
    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public long getItemId(int arg0) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public View getView(final int pos, View v, ViewGroup arg2) { 
     // TODO Auto-generated method stub 
     if (v == null) { 
      LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = inflater.inflate(R.layout.checkboxlist, null); 
      checkBox = (CheckBox) v.findViewById(R.id.btn_chck); 
      sender = (TextView) v.findViewById(R.id.text_senderno); 
      message = (TextView) v.findViewById(R.id.text_msg); 
     } 
     sender.setText("" + new NotifiCation().senderlist.toArray()[pos]); 
     message.setText("" + new NotifiCation().msglist.toArray()[pos]); 

     checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

      @Override 
      public void onCheckedChanged(CompoundButton buttonView, 
        boolean isChecked) { 
       // TODO Auto-generated method stub 
       if (buttonView.isChecked()) { 

       } 

      } 

     }); 
     return v; 
    } 
} 

그리고 이것은 나의 주요 활동이다. 여기에는 기본 체크 박스가 있습니다.

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.delete_notifications); 
    db = new DB(NotificationsDelete.this); 
    notifications = (ListView) findViewById(R.id.list_with_ckbox); 
    selectAll = (CheckBox) findViewById(R.id.btn_checkall); 
    done = (Button) findViewById(R.id.done_notification_delete); 
    notifications.setAdapter(new customListAdpter(con)); 
    selectAll.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

     @Override 
     public void onCheckedChanged(CompoundButton chkbox, boolean arg1) { 
      if (chkbox.isChecked() == true) { 
       for (int i = 0; i < new NotifiCation().senderlist.size(); i++) { 
        //notifications.setItemChecked(i, true); 
        customListAdpter adpter=new customListAdpter(con); 
        adpter.checkBox.setChecked(true); 
       } 
      } else { 
       // new customListAdpter(con).checkBox.setChecked(true); 
      } 

     } 
    }); 
    done.setOnClickListener(this); 

} 

답변

0

selectAll 확인란 필드의 onCheckedChanged()를 처리 한 후에 notifyDataSetChanged()를 호출 해보십시오.