Steve C. Steve C. - 5 months ago 23
Java Question

How to add items from ArrayList<Model> to ArrayList<String> in Android?

I've been searching all over the internet and SO for hours. I've seen numerous examples/answers for how to add items from ArrayList to another ArrayList but can't seem to find anything that explains how to add items from an ArrayList to ArrayList.

I have a wizard that saves selections to two different ArrayList's. The first screen saves the selected items to an ArrayList, another screen saves selected items to an ArrayList then the last screen displays the total items selected from the ArrayList.

I've tried

but that gives the error that String cannot be applied to model.

EDIT: Added classes

To clarify and make things more clear as to what I'm working with.
I'm implementing a "wizard" using WizarDroid Library and the page I'm trying to merge two different ArrayList's on is based off of this multi choice tutorial here.

Model Class:

public class NSBaseModel {
private String baseName;

public NSBaseModel(String name)
baseName = name;


public String getBaseName() {
return baseName;


Wizard page:

public class FormStepBase extends WizardStep {

ArrayList<NSBaseModel> baseNames;
ArrayList<NSBaseModel> selectedItems = new ArrayList<NSBaseModel>();
NSBaseAdapter myAdapter;
ListView myListView;

//You must have an empty constructor for every step
public FormStepBase() {

//Set your layout here
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
List<String> Lines = Arrays.asList(getResources().getStringArray(R.array.NAL_smoothie_base));

baseNames = new ArrayList<NSBaseModel>();
baseNames.add...//Long list of items here

View v = inflater.inflate(R.layout.step_base, container, false);

myListView = (ListView)v.findViewById(;
myAdapter = new NSBaseAdapter(v.getContext(), R.layout.row_base_layout, baseNames);

return v;


* Called whenever the wizard proceeds to the next step or goes back to the previous step

public void onExit(int exitCode) {
switch (exitCode) {
case WizardStep.EXIT_NEXT:

final SparseBooleanArray checkedItems = myListView.getCheckedItemPositions();
int checkedItemsCount = checkedItems.size();
for (int i = 0; i < checkedItemsCount; ++i) {
// Item position in adapter
int position = checkedItems.keyAt(i);
// Add team if item is checked == TRUE!
for (int i = 0; i < selectedItems.size(); i++) {
System.out.print("option list size");

//reference to static ArrayList<String> here

if(selectedItems.size() < 2)
Toast.makeText(getContext(), "Need to select two or more items.", Toast.LENGTH_SHORT).show();
// Just logging the output.
for(NSBaseModel t : selectedItems)
Log.d("SELECTED TEAMS: ", t.getBaseName());
//Thought I could get the strings from here since they show in the logcat


case WizardStep.EXIT_PREVIOUS:
//Do nothing...


In my CreateList class I have
public static ArrayList<String> nsList = new ArrayList<String>();


Solved my issue thanks to @Polichronis Charitidis. His answer ended up being the correct solution. The reason it wasn't working for me is because I had declared
int i
in both my for loops thus confusing the system and result. I had to change the
int i
variable in my second for loop to a different letter and now it works. This is how my second "for" loop looks now.

for (int j = 0; j < selectedItems.size(); j++) {
System.out.print("option list size");



you need to change this line


to this:


so that you can add the String name from the Model ArrayList to the String ArrayList.