1

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?

3 Answers3

2

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).

Alex S. Diaz
  • 2,637
  • 2
  • 23
  • 35
  • Thanks for your answer,is there any ways to update my string's data without updating the app? Because sometimes i'll change the dropdown list data – Alfa Renaldo Aluska Jul 24 '15 at 10:56
  • you could create an empty dropdown list, then read an online xml that contains all your items and add them dinamically, but I don't know if this could be good for your app performance since you have to read an online file – Alex S. Diaz Jul 24 '15 at 11:01
  • How about make a new button with text "Update App Data" to update the items? – Alfa Renaldo Aluska Jul 24 '15 at 11:07
0

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

Community
  • 1
  • 1
Adam86
  • 31
  • 1
  • 4
0

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.

Bonatti
  • 2,778
  • 5
  • 23
  • 42