0

I filled the list with some string values..Then after on item click...I'm able to see the Toast message for all checked items...Well the issue is that I want to move the indexes/string/position to a string and display it on next tab...But on next tab it gives me the item which I checked first...

protected void onListItemClick(ListView l, View v, int position, long id) {
        //final ViewHolder viewHolder = new ViewHolder();
        SparseBooleanArray sp=getListView().getCheckedItemPositions();

        String str="";
        for(int i=0;i<sp.size();i++)
        {
            str+=items[sp.keyAt(i)]+",";
        }
        Toast.makeText(this, ""+str, Toast.LENGTH_SHORT).show();

        Product.pro_selected= l.getItemAtPosition(position).toString();;

I use the following to display all selected item..

txtPro=(TextView)findViewById(R.id.select_pro_name); 
                txtPro.setText(Product.pro_selected);
Numair
  • 1,062
  • 1
  • 20
  • 41
  • check this [link](http://stackoverflow.com/questions/9450058/using-checkbox-to-filter-contacts-and-get-phone-number/10105655#10105655) – Satheeshkumar May 03 '12 at 11:17

1 Answers1

0
protected void onListItemClick(ListView l, View v, int position, long id) {

    ArrayList<String> itemSelected = new  ArrayList<String>();
    itemSelected.add(presidents[position]);
 }

This code is placed from you navigate to next activity/Screen

    Intent i = new Intent(getApplicationContext(),Second.class);
    i.putStringArrayListExtra("SelectedItems", itemSelected);
    startActivity(i);

in Second Activity get the value of intent and use it.

Intent intent = getIntent();
ArrayList<String> items = new ArrayList<String>();
items = intent.getStringArrayListExtra("SelectedItems");

This will shows you all selected items.

for (int i = 0; i < items.size(); i++) {

Toast.makeText(getApplicationContext(), String.valueOf(items.get(i)), Toast.LENGTH_SHORT).show();
}

To display them in a List extends ListActivity

ListView listView = getListView();
listView.setChoiceMode(listView.CHOICE_MODE_NONE);

setListAdapter(new ArrayAdapter<String>
                (this,android.R.layout.simple_list_item_1,items));

To display Selected items

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), items[position], Toast.LENGTH_SHORT).show();
        super.onListItemClick(l, v, position, id);
    }
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
  • how to get the value for second activity...i used **Bundle extras = getIntent().getExtras(); String selected = extras.getString("Selected");** but it just display next layout when i click any of the item... – Numair May 03 '12 at 12:03
  • no man....same result...there are 10 items in the list...on every item click it take me to next layout.. – Numair May 03 '12 at 12:17
  • Oh yes you have to give user an Button or OptionMenu to navigate to next activity and write the above there. There is no other way to achieve this. – Krishnakant Dalal May 03 '12 at 12:20
  • alright..got that...but still one issue left...it display only single item, however task is to display all the checked items on the next tab/layout, leaving back the unchecked items.. – Numair May 03 '12 at 12:23
  • it gives me the value which i clicked last...i used the **txtPro=(TextView)findViewById(R.id.select_pro_name); txtPro.setText(Product.pro_selected);** in my total.xml, do i've use a list or what? – Numair May 03 '12 at 12:37
  • i'm still having problem to display the multiple values..however your ans helps me alot...it would be more appreciatd if you help me in that part too... – Numair May 04 '12 at 05:01
  • Ok just tell me what you want to do in second activity – Krishnakant Dalal May 04 '12 at 05:05
  • the items which i check are populated in a list...for eg i check 5 items..then after submit button it should display me the checked items..leaving back the unchecked... – Numair May 04 '12 at 05:21
  • Check the post now and upvote and accept if you find it useful – Krishnakant Dalal May 04 '12 at 05:28
  • First check the values of Arraylist items, Using the for loop and Toast – Krishnakant Dalal May 04 '12 at 05:55
  • Whats the output of for loop Toast?? – Krishnakant Dalal May 04 '12 at 06:39
  • Stop thinking and check using debugger – Krishnakant Dalal May 04 '12 at 06:50