0

I have the following listview : http://www.vogella.de/articles/AndroidListView/article.html the chaper: 8. Tutorial: Domain Model and Rows interaction

In MyList class, in the OnCreate() method I've added:

setContentView(R.layout.button), where the layout button is containting:

<ListView
android:id="@android:id/list"
...
</ListView>

After pressing the OK button I would like to print all the checked elements from the ListView. How to do that? Need help. Appreciate

user1222905
  • 533
  • 2
  • 17
  • 36

2 Answers2

0

Just make the list in getModel() public. Then in the activity use the following

private void getSelected(){
    for(int i=0;i<list.size();i++){
            if(list.get(i).isSelected()){
                    Log.d(TAG,"The item is selected"+list.get(i).getName();
                    //Do the processing you need here.
            }
    }
}

Call getSelected() method from where you want.

user936414
  • 7,574
  • 3
  • 30
  • 29
  • how to make the list in the getModel()? I need in the list just the checked elements. Please help – user1222905 Mar 28 '12 at 09:16
  • make the list object in getModel() function a class object. private List list = new ArrayList(); – user936414 Mar 28 '12 at 09:19
  • I did the getMOdel method public. I am gioing to insert the methos you wrote and test it. WIll this methid print all the selected element? I want to create a list that keeps the selected elements till I delete them programatically. How to do this? Thx!! – user1222905 Mar 28 '12 at 09:29
  • IT WORKS!!! HOW TO PUT THIS IN A LIST AND DISPLAY THEM IN A NEW LAYOUT ON THE CLIENT SIDE? – user1222905 Mar 28 '12 at 09:37
0

Create an arraylist of strings in your activity..

list str = new list();

and in onclick of your list items.. check if that specific check box is checked or not..

if(CheckbxsetChecked(true))
{
 str.add(**"text in that row"**)
 }
 else if(CheckbxsetChecked(false))
   {
 str.remove(**"text in that row"**)
 }

now display this list with new adapter in onclick of your button

5hssba
  • 8,079
  • 2
  • 33
  • 35