Separate a string in Java

1

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 got it 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 {ctPay.getMyPayments ()}; Looks 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 в 19:36
source

1 answer

1

With this you would hardcodeando the line break

 Lista.add(json.get("title").toString() + "\t\t");

Added, Solution pass parameters like ArrayList ():

new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ctPagar.getMetodosPagos());
    
answered by 24.07.2018 / 19:55
source