Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class that generates a name and 3 checkboxes, I put them in an arraylist / arrayadapter, I would now like to list it in a listview, but I don't know how to put it so that it generates the name and the 3 checkbox boxes in each horizontal of the listview


What I have tried:

private void initListViewData()  {

       animal donald = new animal("Donald", false,false,true);
       animal aaa = new animal("aaaaa");
       animal bbb = new animal("bbbbbbbbb", false,false,false);
       animal[] users = new animal[]{bbb,aaa, donald};

       // android.R.layout.simple_list_item_checked:
       // ListItem is very simple (Only one CheckedTextView).
       ArrayAdapter<animal> arrayAdapter
               = new ArrayAdapter<animal>(this, android.R.layout.simple_list_item_checked, users);

     //pone el arrayadapter en el listview
       this.lv1.setAdapter(arrayAdapter);

       for(int i=0;i< users.length; i++ )  {
           this.lv1.setItemChecked(i,users[i].isActive());
           this.lv1.setItemChecked(i,users[i].isActive2());
           this.lv1.setItemChecked(i,users[i].isActive3());
       }
   }
Posted
Updated 23-Oct-20 0:45am
Comments
David Crow 23-Oct-20 8:52am    
Each row of the ListView needs its own layout (rather than using simple_list_item_checked). That "row" layout will contain a TextView and three CheckBox controls.

1 solution

 
Share this answer
 
Comments
ebsigma 23-Oct-20 7:00am    
I already found out with those links but what I am looking for is that each line of the listview has 3 checkboxes and that the changes are saved when the app is closed

name1 [] [x] []
name2 [] [x] [x]
name3 [] [] []
Richard MacCutchan 23-Oct-20 7:32am    
You need to capture the values of the checkboxes (and any other data you need) and store it in an internal or external data file: Data and file storage overview  |  Android Developers[^].
ebsigma 26-Oct-20 5:33am    
but first I want to generate the checkboxes from code, that if in a database it has a true or false boolean check, it generates the selected or unselected checkbox in the listview
Richard MacCutchan 26-Oct-20 5:44am    
Yes, and that is what I suggested in my previous comment. Once you have saved the values then you can restore them next time the application starts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900