I'm trying to create an Android class that creates a list of other applications for later display, so far I have the following code to create a list (taken from a Google example):
public final class AppList {
public static List<App> list;
public static List<App> setupApp() {
list.add(buildAppInfo(
"Browsers",
"chrome",
"description",
"Google Inc.",
"com.android.chrome",
"http://...",
"http://..."
));
list.add(buildAppInfo(
"Browsers",
"Firefox",
"description",
"Mozilla",
"com.mozilla.firefox",
"http://...",
"http://..."
));
[An so on...]
return list;
}
private static App buildAppInfo(String category,
String title,
String description,
String developer,
String packageName,
String iconImageUrl,
String bgImageUrl) {
App app = new App();
app.setId(App.getCount());
App.incCount();
app.setTitle(title);
app.setDescription(description);
app.setDeveloper(developer);
app.setCategory(category);
app.setIconImageUrl(iconImageUrl);
app.setBackgroundImageUrl(bgImageUrl);
app.setPackageName(packageName);
return app;
}
}
Instead, I would like to dynamically load data from a web server, which I can configure to feed either JSONArray or XML, and then put that data into a list. For what I read, I could use Volley, but I am not very experienced in Volley or Java at all (I just learned on the road), so I don’t need to think much about how to proceed.
I found an example from the Google Developers site . I was thinking of adding something like this:
public final class AppList {
public static List<App> list;
public static List<App> setupApp() {
String url = "https://json_url/";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
list.add(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
return list;
}
private static App buildAppInfo(String category,
String title,
String description,
String developer,
String packageName,
String iconImageUrl,
String bgImageUrl) {
App app = new App();
app.setId(App.getCount());
App.incCount();
app.setTitle(title);
app.setDescription(description);
app.setDeveloper(developer);
app.setCategory(category);
app.setIconImageUrl(iconImageUrl);
app.setBackgroundImageUrl(bgImageUrl);
app.setPackageName(packageName);
return app;
}
}
The data received from the server feed should look something like this:
buildAppInfo(
"Browsers",
"Firefox",
"description",
"Mozilla",
"com.mozilla.firefox",
"http://...",
"http://..."
)
buildAppInfo(
"Browsers",
"Firefox",
"description",
"Mozilla",
"com.mozilla.firefox",
"http://...",
"http://..."
)
[...]
, , . -, , , ? .