Break line in json string java

后端 未结 3 1178
失恋的感觉
失恋的感觉 2021-01-28 07:46

Don\'t know how to express myslef very well.As you see down in my code I have a String,an ArrayList of Strings and a spinner.

In my code I add the elements of my String

相关标签:
3条回答
  • 2021-01-28 08:00

    Modify your string which will be shown in spinner like this

    StringBuffer accounts = new StringBuffer("one");
    stringBuffer.append("\n");
    stringBuffer.append("two");
    stringBuffer.append("\n");
    stringBuffer.append("three");
    stringBuffer.append("\n");
    stringBuffer.append("four");
    

    TextView in the spinner will populate the values in different lines provided height and width is wrap_content

    0 讨论(0)
  • 2021-01-28 08:20

    Try below code.

     ArrayList<String> spinnerAccounts = new ArrayList<>(); // I don't know the use of this ArrayList
     Spinner accounts = (Spinner)findViewById(R.id.accounts);
     ArrayAdapter<String> adapter =
           new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,spinnerAccounts);
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     accounts.setAdapter(adapter);
     spinnerAccounts.add("one");
     spinnerAccounts.add("two");
     spinnerAccounts.add("three");
     spinnerAccounts.add("four");
     adapter.notifyDataSetChanged();
    

    Add items you want to display in Spinner using spinnerAccounts.add("ACCOUNT_NAME") method.

    Hope It'll help you.

    0 讨论(0)
  • 2021-01-28 08:22

    Change u r code "accounts" used two times. Make arraylist for accounts and load into spinner.

        Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
        List<String> accountsList = new ArrayList<String>();
        accountsList.add("one");
        accountsList.add("two");
        accountsList.add("three");
        accountsList.add("four");
    
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
                     (this,android.R.layout.simple_spinner_item,accountsList);
    
        dataAdapter.setDropDownViewResource
                     (android.R.layout.simple_spinner_dropdown_item);
    
        spinner1.setAdapter(dataAdapter);
    
        // Spinner item selection Listener  
        addListenerOnSpinnerItemSelection();
    
        // Button click Listener 
        addListenerOnButton();
    

    Follow this Tutorial

    0 讨论(0)
提交回复
热议问题