this is my function.
public List<DanhLam> ActionBarViewFlipper(final int id_dia_diem, String url){
RequestQueue requestQueue = Volley.newRequestQueue(this);
getDataDanhLamForViewFlipper = new ArrayList<>();
StringRequest MyStringRequest =
new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//This code is executed if the server responds, whether or not the response contains data.
//The String 'response' contains the server's response.
try {
JSONArray object = new JSONArray(response);
for (int i = 0;i< object.length();i++) {
JSONObject jsonObject = new JSONObject();
jsonObject = (JSONObject) object.get(i);
getDataDanhLamForViewFlipper.add(new DanhLam(jsonObject.getInt("id"),
jsonObject.getString("ten_danh_lam"),
jsonObject.getInt("phanloai"),
jsonObject.getInt("id_dia_diem"),
jsonObject.getString("thong_tin_danh_lam"),
jsonObject.getString("img_danh_lam"),
jsonObject.getDouble("latitude"),
jsonObject.getDouble("longtitude")));
}
ArrayList<String> mangqc = new ArrayList<>();
for (int i = 0;i<getDataDanhLamForViewFlipper.size();i++){
mangqc.add(getDataDanhLamForViewFlipper.get(i).getImg_danh_lam());
}
for (int i = 0;i<mangqc.size();i++){
ImageView imageView = new ImageView(getApplicationContext());
Picasso.get().load(mangqc.get(i)).into(imageView);
viewlipper.addView(imageView);
}
viewlipper.setFlipInterval(5000);
viewlipper.setAutoStart(true);
Animation animation_slide_in = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_in_right);
Animation animation_slide_out = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_out_right);
viewlipper.setInAnimation(animation_slide_in);
viewlipper.setOutAnimation(animation_slide_out);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "asdf", Toast.LENGTH_LONG).show();
}
}
){
protected Map<String, String> getParams() {
Map<String, String> MyData = new HashMap<String, String>();
MyData.put("id_dia_diem", String.valueOf(id_dia_diem)); //Add the data you'd like to send to the server.
return MyData;
}
};
requestQueue.add(MyStringRequest);
return getDataDanhLamForViewFlipper;
}