user1708134
user1708134

Reputation: 673

Items selected in listview with checkbox

How do i get the selected items in my listview with check box, i search for an answer to this but nothing is clear enough for me to under stand

here's my listview

public void laptopTab() {
        List<String> listDisplay = new ArrayList<String>();
        for (int counter = 0 ; counter<laptopFilter.length;counter ++) {
            listDisplay.add(laptopFilter[counter]);
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.filter_listview, 
                R.id.filter_name,listDisplay);

        laptopLV = (ListView) findViewById(R.id.laptopLV);
        laptopLV .setAdapter(adapter);
        laptopLV.setOnItemClickListener(this);
    }

and here is my code for my onItemClickListener

public void onItemClick(AdapterView<?> arg0, View v, int position ,
            long id) {
        // TODO Auto-generated method stub
        if (v != null) {
            cb = (CheckBox)v.findViewById( R.id.cb ); 
            cb.setChecked(!cb.isChecked());
        }
        switch (th.getCurrentTab()) {
        case 0:
            if(cb.isChecked()){
                th.getTabWidget().getChildTabViewAt(1).setEnabled(false);
                th.getTabWidget().getChildTabViewAt(2).setEnabled(false);
                selectedFromLaptopList.add(laptopLV.getItemAtPosition(position).toString());
            }

            else {
                th.getTabWidget().getChildTabViewAt(1).setEnabled(true);
                th.getTabWidget().getChildTabViewAt(2).setEnabled(true);
            }
            break;
        case 1:
            if(cb.isChecked()){
                th.getTabWidget().getChildTabViewAt(0).setEnabled(false);
                th.getTabWidget().getChildTabViewAt(2).setEnabled(false);
                selectedFromMp3List.add(mp3LV.getItemAtPosition(position).toString());
            } else {
                th.getTabWidget().getChildTabViewAt(0).setEnabled(true);
                th.getTabWidget().getChildTabViewAt(2).setEnabled(true);
            }
            break;
        case 2:
            if(cb.isChecked()){
                th.getTabWidget().getChildTabViewAt(0).setEnabled(false);
                th.getTabWidget().getChildTabViewAt(1).setEnabled(false);
                selectedFromMobileList.add(mobileLV.getItemAtPosition(position).toString());
            } else {
                th.getTabWidget().getChildTabViewAt(0).setEnabled(true);
                th.getTabWidget().getChildTabViewAt(1).setEnabled(true);
            }
        default:
            break;
        }
    }

i have a listview inside a tabhost so i just have to disable the other tab if one checkbox is selected on a current tab

and i have a button. there i want to know all items selected on the listview

please help me and thanks in advance

Upvotes: 0

Views: 338

Answers (1)

Rahul Patil
Rahul Patil

Reputation: 2727

Can you use the code or answer mention in the link android listactivity onCheckedChangeListener and also make use of mListview.getCheckedItemPositions()

Upvotes: 2

Related Questions