Reputation: 179
How can i get android:text with online strings?
My code
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_contrnt"
android:text="@array/mylist"/>
I've tried
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_contrnt"
android:text="@http://myUrl.com/strings.xml"/>
Inside strings.xml in my server
<resources>
<string-array name="mylist">
<item>My Item1</item>
<item>My Item2</item>
</string-array>
</resources>
but it's fail
How can i do that?
Upvotes: 1
Views: 241
Reputation: 2781
You cannot access resources from the outside of the scope of the application. Start from here then, when you understand what is needed to gather the info, use this instead, as its better.
You need to have the following:
1 - The information you are seeking, for this answer I will suppose you have your own apache server with a PHP response method: "www.MyServer.com/getColors.php
2 - The class you are using the information
3 - Another class/service/asynctask to gather the info.
There are several ways for you to gather that data. If its likely that the data does not change much, I suggest checking the information when the app begins (the onCreate function) if the data changes a lot, I suggest doing it on the button onClick method instead.
Upvotes: 1
Reputation: 2667
AFAIK you can't access online resources, as the official site says:
You should place each type of resource in a specific subdirectory of your project's res/ directory. [...] the res/ directory contains all the resources (in subdirectories).
Upvotes: 2
Reputation: 31
This is what you need:
// Array of choices
String colors[] = {"Red","Blue","White","Yellow","Black","Green","Purple","Orange","Grey"};
// Selection of the spinner
Spinner spinner = (Spinner) findViewById(R.id.myspinner);
// Application of the Array to the Spinner
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
spinner.setAdapter(spinnerArrayAdapter);
Find here
Upvotes: 0