Break Line In Json String Java
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 in my ArrayL
Solution 1:
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
usingspinnerAccounts.add("ACCOUNT_NAME")
method.
Hope It'll help you.
Solution 2:
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
Solution 3:
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
Post a Comment for "Break Line In Json String Java"