Volley kütüphanesine göz atın, istekte bulunmak için Google tarafından hazırlanmış bir kütüphane.
here you have some explications about Volley. Projenizde volley kütüphanesi almanız gerekecek.
public class MyRequest {
private Context context;
private RequestQueue queue;
public MyRequest(Context context, RequestQueue queue) {
this.context = context;
this.queue = queue;
}
public void getArticles(final GetArticlesCallback callback){
String url = "YourScriptUrl";
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
callback.onSuccess("I will get this string in the activity");
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.onError("erreur : " + error.toString());
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<>();
map.put("tag", "postArgument1");
map.put("tag2", "postArgument2");
return map;
}
};
queue.add(request);
}
public interface GetArticlesCallback{
void onSuccess(String success);
void onError(String error);
}
}
Ve siz aktivitesinde bu sınıf çağrı:
//queue is a RequestQueue
//request is a Myrequest
queue = VolleySingleton.getInstance(this).getRequestQueue();
request = new MyRequest(this, queue);
request.getArticles(new MyRequest.GetArticlesCallback() {
@Override
public void onSuccess(String success) {
}
@Override
public void onError(String error, String id) {
}
});
Google (Here called mySingleton) tarafından verilen tekil sınıf oluşturmak için ve bu bir benzeri koduyla bir istek sınıf oluşturmak zorunda
Lütfen herkese cevap verin – Donald
Merhaba, haklıysam, tablonuzun verilerini uygulama kodunuza nasıl alacağınızı bilmek ister misiniz? –
Evet lütfen ...... – Donald