Fixed, the problem was in my adapter:

// Categories / Folders Adapter for Spinner View
    public class spAdapter extends BaseAdapter implements OnClickListener {
        private ArrayList<String> m_arySelItems;
        private LayoutInflater m_layoutInfater;
        private ArrayList<String> m_aryFolders;

        public spAdapter(Context context,
                            int textViewResourceId,
                            ArrayList<String> aryFolders) {
            m_aryFolders     = aryFolders;
            m_arySelItems     = new ArrayList<String>();
            m_layoutInfater =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        public void add(String item) {
            m_aryFolders.add(item);
        }

        public void clear() {
            m_aryFolders.clear();
        }

        public int getCount() {
            return m_aryFolders.size();
        }

        public Object getItem(int position) {
            return position;
        }

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

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

            try{
                if ( vi == null ) {
                    vi = m_layoutInfater.inflate(R.layout.spfolders, null);
                }
// Get the folder from the current position in the array
                CheckBox chkBox = (CheckBox)vi.findViewById(R.id.chkBox);
                String strFolder = m_aryFolders.get(position);

                if ( chkBox != null && strFolder != null ) {
                    chkBox.setText(strFolder);
                    chkBox.setChecked(m_arySelItems.contains(strFolder));
                    chkBox.setOnClickListener(this);
                }
            } catch( Exception ex ) {
                Log.e( TAG, ex.getMessage() );
            }
            return vi;
        }

        @Override
        public void onClick(View v) {
            CheckBox chkBox = (CheckBox)v;
            String strFolder = chkBox.getText().toString();

            if ( chkBox.isChecked() ) {
                if ( m_arySelItems.contains(strFolder) == false ) {
                    m_arySelItems.add(strFolder);
                }
            } else {
                if ( m_arySelItems.contains(strFolder) == true ) {
                    m_arySelItems.remove(strFolder);
                }
            }
        }
    }



On Sun, Jul 17, 2011 at 9:42 AM, Simon Platten <[email protected]
> wrote:

> I have a spinner with a checkbox in it, here is the XML for the item:
>
> <?xml version="1.0" encoding="utf-8"?>
> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android";
>                      android:layout_width="fill_parent"
>
>  android:layout_height="?android:attr/listPreferredItemHeight"
>                      android:padding="10dp">
>     <CheckBox android:id="@+id/chkBox"
>                  android:layout_width="fill_parent"
>                  android:layout_height="wrap_content"
>                  android:text="Folder name"
>                 android:textColor="@color/black"
>                 android:soundEffectsEnabled="true"/>
> </RelativeLayout>
>
> Here is the adapter code:
>
>     public class spAdapter extends BaseAdapter implements OnClickListener {
>         private ArrayList<String> m_arySelItems = new ArrayList<String>();
>         private LayoutInflater m_layoutInfater;
>         private ArrayList<String> m_aryFolders;
>
>         public spAdapter(Context context,
>                             int textViewResourceId,
>                             ArrayList<String> aryFolders) {
>             m_aryFolders     = aryFolders;
>             m_layoutInfater =
> (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>         }
>
>         public void add(String item) {
>             m_aryFolders.add(item);
>         }
>
>         public void clear() {
>             m_aryFolders.clear();
>         }
>
>         public int getCount() {
>             return m_aryFolders.size();
>         }
>
>         public Object getItem(int position) {
>             return position;
>         }
>
>         public long getItemId(int position) {
>             return position;
>         }
>
>         public View getView(int position,
>                             View convertView,
>                             ViewGroup parent) {
>             View vi = convertView;
>
>             try{
> // Get the Actual Image from the Array
>                 String strFolder = m_aryFolders.get(position);
>
>                 if ( vi == null ) {
>                     vi = m_layoutInfater.inflate(R.layout.spfolders, null);
>                 }
>                 CheckBox chkBox = (CheckBox)vi.findViewById(R.id.chkBox);
>                 chkBox.setText(strFolder);
>                 chkBox.setTag(strFolder);
>
>                 if ( m_arySelItems.contains(strFolder) ) {
>                     chkBox.setChecked(true);
>                 }
>                 chkBox.setOnClickListener(this);
>             } catch( Exception ex ) {
>                 Log.e( TAG, ex.getMessage() );
>             }
>             return vi;
>         }
>
>         @Override
>         public void onClick(View v) {
>             CheckBox chkBox = (CheckBox)v;
>             String strFolder = (String)chkBox.getTag();
>
>             if ( chkBox.isChecked() ) {
>                 if ( m_arySelItems.contains(strFolder) == false ) {
>                     m_arySelItems.add(strFolder);
>                 }
>             } else {
>                 if ( m_arySelItems.contains(strFolder) == true ) {
>                     m_arySelItems.remove(strFolder);
>                 }
>             }
>         }
>     }
>
> I've done something wrong in the getView, something is missing because when
> I scroll off view, any selections get mixed up.  Is there a good example /
> tutorial where I can find out how to implement this correctly?
>
> Thank you,
>
> --
> Regards,
> Sy
>
>


-- 
Regards,
Sy

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to