0

I have the next String in Eclipse

"actif,fernando,enrique" 
//this will be variable with commas

How split this String? and add to a list view with a "FOR"? in Eclipse / Android Java

I need ListView Or Spinner like this:

actif
_______
fernando
________
enrique

2 Answers2

2
String[] list = "your string".split(",");

For listView:

 ArrayAdapter<CharSequence> adapter =  new ArrayAdapter<CharSequence>(this,android.R.layout.simple_list_item_1,list);
                yourListViewvariable.setAdapter(adapter);

Update for spinner:

private Spinner spinner = (Spinner)findViewById(R.id.yourSpinnerId);
ArrayAdapter<CharSequence> adapter =  new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item,list);
                adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
                spinner.setAdapter(adapter);
Adnan Ali
  • 792
  • 1
  • 8
  • 21
0

You can try this way:

String input = "actif,fernando,enrique";

try {
    String[] splitArray = input.split(",");
    for(String s : splitArray){
        yourAdapter.add(s);
    }
} catch (PatternSyntaxException ex) {

}

Assuming that your adapter is of type String

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174