Answer the question
In order to leave comments, you need to log in
How to get a local json file and output a list?
There is a JSON file with a bunch of objects and arrays. It is necessary to parse it and subsequently display the values of the necessary keys in the list.
This option raises no questions. Everything is clear here:
public class MainActivity extends ListActivity {
private ArrayAdapter<String> myAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String[] simpleArray = new String[] { "Первый", "Второй", "Третий" };
myAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, simpleArray);
setListAdapter(myAdapter);
}
}
Answer the question
In order to leave comments, you need to log in
You need to use AssetManager . You can get an instance of it with Context.getAssets(). Parse the file with either standard JsonObject/JsonArray or something like Gson.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question