views:

348

answers:

4

I'm building a list of contacts, where the user can select more than one one contact. Currently the android layouts only provide a multiple select with a single textview and a checkbox, what I want to do is have the name and number and a checkbox (two textviews and a checkbox). When I implement this with a custom layout, and when the user clicks on the list, the check boxes don't get ticked. I tried to bind the checkbox to the listview but it didnt work. Any help would be much appreciated.

A: 

I found a solution for this, will post the code shortly.

Hades
A: 

I also have this problem..would you mind posting the code? thank you very much

Prue
ragsession.com/ContactSelection2.java
Hades
A: 
private class EfficientAdapter extends BaseAdapter implements ListView.OnScrollListener  {


    private LayoutInflater mInflater;

     public EfficientAdapter(Context context) {
         mInflater = LayoutInflater.from(context);  

     }

     public int getCount() {            
         return c.getCount();
     }

     public Object getItem(int position) {           

         return position;
     }

     public long getItemId(int position) {
         return position;
     }  

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

         ViewHolder holder;

         if (convertView == null) {

             convertView = mInflater.inflate(R.layout.customcontactlist, null);              
             holder = new ViewHolder();               
             holder.txtName = (CheckedTextView) convertView.findViewById(R.id.TextView01);
             holder.txtNumber = (TextView) convertView.findViewById(R.id.TextView00);                
             convertView.setTag(holder);    

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


         if (hashtable.contains(position)) {
             holder.txtName.setChecked(true);
         }else{
             holder.txtName.setChecked(false);
         }
         return convertView;
     }

      class ViewHolder {
         CheckedTextView txtName;
         TextView txtNumber;         
       }

        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
        }

        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }                   
     }

l1.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {          

            EfficientAdapter.ViewHolder holder;
            holder = (EfficientAdapter.ViewHolder) arg1.getTag();


            if(holder.txtName.isChecked()){
                holder.txtName.setChecked(false);
            }else{
                holder.txtName.setChecked(true);
            }                               
        }               
    });     
Hades
A: 

Hi please post complete code I am also getting this problem...

Creative-MITian
ragsession.com/ContactSelection2.java
Hades