简体   繁体   中英

Setting up checkboxes dynamically in a layout

For the past couple of days I have been racking my brain over how to exactly take each element in a number of string arrays and place them in checkboxes which would then be placed into a Linear Layout. Each time the user selects something from a radio button group (which is in one tab), the contents of these Linear Layouts (which are contained in an overarching Linear Layout) would be changed with respect to whichever radio button was selected. So it would go something like this:

[User selects something in this tab with radio buttons] -> [This tab over here is updated]

The tab in question:

  • [Linear Layout]

    • [Linear Layout]
      • [x] String1
      • [x] String2
      • [x] String3

I have tried using a ListView, but the contents of each line of the list need to be easily selectable (hence using the checkboxes). I have thought of trying out the MergeAdapter but I would have to some how change the arrays that are fed to it each time there is an update (and I'm not using SQLite nor Cursors).

So might anyone have a suggestion to remedy this problem?

[Edit] Sorry if my intent was not so clear. I have written an Adapter which takes in an array of strings and, if set to a ListView, will show put a checkbox in each line of the List. What I would like instead is to just make a checkbox with the text in it set to one of the elements of the array and added to one of the LinearLayouts. This would go through the complete array. This way, I would have multiple sets of checkboxes that the user can select from. The code (or pseudo code) would look something like this:

for (int i = 0; i < someArrayAdapter.size; i++) {
  ListView.addView(someArrayAdapter.getView(i, someConverView, someGroupView));
}

Where someArrayAdapter is a custom adapter. I found I can't actually use getView() like that so I need to use some other method (which is why I'm asking here;) ).

Check out my earlier answer on a very similar question . It may give you the answer you're looking for. Otherwise, let me know and I'll try to explain more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM