Hi,
I am to display the list and store the selected items in an array. But
I am not able to get the correct items that were selected.
Here whenever the user clicks an item, the array is getting updated,
irrespective if the user is clicking the item to select it or deselect
it. Could some one please help me solve this. I could actually perform
an iteration to remove the odd numbered items in the array but I feel
that would become an overload on the phone. Is there something for
efficient. Please advise.


public class MainActivity extends ListActivity {
        TextView selection;
        String[] items={"sodium", "O2", "C02", "HCL", "NaCl",
                                        "H2So4", "O3", "Ag"};
        String names[] = new String[10];
        static int i=0; int posarray[] = new int[10];
        @Override
        public void onCreate(Bundle icicle)
       {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                setListAdapter(new ArrayAdapter<String>(this,
                                                                                
                android.R.layout.simple_list_item_multiple_choice,
                                                                                
                items));
                ListView listView = getListView();
                listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
                selection=(TextView)findViewById(R.id.selection);
        }

        public void onListItemClick(ListView parent, View v, int position,
                                                                                
                        long id)
        {
                        posarray[i]=position;

                        if(!check(position))
                        {
                                names[i]= items[position];
                        }
                                selection.setText(arrayToString(names));i++;


        }

        private boolean check(int position) {
                for(int k=0;k<posarray.length;k++){
                        if(posarray[k]==position)
                        {
                                posarray[k]=100;
                                return true;
                        }

                }
                return false;

        }

        public String arrayToString(String[] stringarray){
            String str = " ";
            for (int i = 0; i < stringarray.length; i++) {
              str = str + stringarray[i];
            }
            return str;
          }
}







Thanks,
Raqeeb

-- 
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