separate chain for a spinner

0

I want to separate this string for a spinner.

Here I receive my JSON I go through it to only get what I want.

JSONObject jsonObject= new JSONObject(responseStrBuilder.toString());
JSONArray jsonArray = jsonObject.getJSONArray("payment_methods");

ArrayList<String> Lista = new ArrayList<>();
for(int i=0;i<jsonArray.length();i++){
    try {
        JSONObject json = jsonArray.getJSONObject(i);
        //Aquí se obtiene el dato y es guardado en una lista
        Lista.add(json.get("title").toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

ctOnGo.setMetodosPagos(Lista.toString());
  

ctOnGo.setMethodsPayments (List.toString ()); This is to save what I extracted from the JSON

The spinner is here

//Spinner
SpinnerMethod = (Spinner) findViewById(R.id.spinner_methodopago);
String[] method = {ctPagar.getMetodosPagos()};
ctPagar.getMetodosPagos().split("\|");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, method);
SpinnerMethod.setAdapter(adapter);

Now I want this to save {ctPagar.getMethodsPosts ()}; to look like this:

  

Check / Money order

     

PayPal

     

Payment on delivery

     

Standard payment

But I get it in a chain: Check / Money order, PayPal, Payment on delivery, Standard payment

    
asked by Andrea Valentina 24.07.2018 в 18:17
source

1 answer

0

If you have the original string:

  

Check / Money order, PayPal, Payment on delivery, Standard payment

Use this split to get the values:

ctPagar.getMetodosPagos().split(",");

Now in each element of the array you must add new line and carriage return "\n\r" , this I guess you would do it within the method getMetodosPagos() , example:

   String[] palabras = s.split(",");
   for(int i = 0 ; i< palabras.length ; i++ ){
       palabras[i] = palabras[i] + "\n\r";     
   }
    
answered by 24.07.2018 в 23:46