You need an Adapter
for your Spinner
. See here http://developer.android.com/resources/tutorials/views/hello-spinner.html
That adapter will hold the values you select using your spinner.
If these are some fixed values then ArrayAdapter can do. You can fill it with values like follows:
public YourActivity extends Activity {
...
private String[] mValues = {"One", "Two", "Three"};
private Spinner mSpinner;
public void onCreate(Bundle bundle) {
...
mSpinner = findViewById(R.id.yourspinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, mValues);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(adapter);
...
}
After this you will have a spinner populated with mValues
. (Alternatively, you can use ArrayAdapter.createFromResource
).
Then, you will have to read your assets file using something like
InputStream is = getAssets().open("your_asset.txt");
For assets see here http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/content/ReadAsset.html
You'll probably need to parse the input stream using JSON parser. I believe Android has a JSON parser class. See for example here http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/
Oh, yes, as posted in the answer below by Anil it's enough to parse the JSON file only once.
Then you need to store the value you found for your spinner element in the database. This gets long to to explain. You can see how to create and use databases in Android docs.