I’m creating a Spinner using an array inside strings.xml.
I notice that I can use android:entries="@array/theName" to populate my spinner.
Or I can use this code:
spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this, R.array.theName, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
So what’s the difference between these two? Does one run faster then the other. I’m all for not using all the code but if its going to cause problem with the rest of my app I would rather use the code. I’m planning on taking what a user selected and using it else where in my app.
Both are valid.
If you have already the string array into your res folder, go with the XML code. It’s simpler and cleaner.
Otherwise if you get your array dynamically (from internet for instance), use the java approach.