If there is an activation, when creating a request is sent to the server and the response is displayed on the screen, there are also 2 buttons when clicking on which should also send data to the server (depending on the button pressed), how can you implement all 3 requests? When the added buttons stopped to display the loaded photo and text. Library volley. As I did:
public class UserActivity extends Activity { private static final String TAG = UserActivity.class.getSimpleName(); private static final String urlUser = "http://test/user.php?code="; private static final String urlLike = "http://test/api/like.php?"; private ProgressDialog pDialog1; private ProgressDialog pDialog2; private Button btnLike; private Button btnDisLike; private static String like_type; private static String like_to; private SQLiteHandler db; ImageLoader imageLoader = AppController.getInstance().getImageLoader(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user); HashMap<String, String> user = db.getUserDetails(); btnLike = (Button) findViewById(R.id.like); btnDisLike = (Button) findViewById(R.id.dislike); final String GetToLike = "unique_id="+user.get("uid")+"like_to="+like_to+"type="+like_type; // like btnLike.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { like_type = "1"; pDialog1 = ProgressDialog.show(UserActivity.this, getString(R.string.processing), getString(R.string.wait)); StringRequest likeReq = new StringRequest(Request.Method.GET, urlLike + GetToLike, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d(TAG, "Like Response: " + response.toString()); hidePDialog1(); try { JSONObject obj = new JSONObject(response); String unique_id = obj.getString("name"); String like_to = obj.getString("like_to"); String type = obj.getString("like_type"); TextView txtLike_status = (TextView) findViewById(R.id.like_status); txtLike_status.setText(like_to); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); hidePDialog1(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(likeReq); } }); // dislike btnDisLike.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { like_type = "0"; pDialog1 = ProgressDialog.show(UserActivity.this, getString(R.string.processing), getString(R.string.wait)); StringRequest likeReq = new StringRequest(Request.Method.GET, urlLike + GetToLike, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d(TAG, "Like Response: " + response.toString()); hidePDialog1(); try { JSONObject obj = new JSONObject(response); String unique_id = obj.getString("name"); String like_to = obj.getString("like_to"); String type = obj.getString("like_type"); TextView txtLike_status = (TextView) findViewById(R.id.like_status); txtLike_status.setText(like_to); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); hidePDialog1(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(likeReq); } }); String Code = getIntent().getStringExtra("code"); pDialog2 = ProgressDialog.show(this, getString(R.string.id_people), getString(R.string.wait)); StringRequest userReq = new StringRequest(Request.Method.GET, urlUser + Code, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d(TAG, "User Response: " + response.toString()); hidePDialog2(); try { JSONObject obj = new JSONObject(response); String name = obj.getString("name"); like_to = obj.getString("like_to"); String second_name = obj.getString("second_name"); String ThumbnailUrl = obj.getString("photo"); imageLoader = AppController.getInstance().getImageLoader(); NetworkImageView thumbNail = (NetworkImageView) findViewById(R.id.thumbnail); TextView txtUser = (TextView) findViewById(R.id.user); thumbNail.setImageUrl(ThumbnailUrl, imageLoader); txtUser.setText(name + " " + second_name); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); hidePDialog2(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(userReq); } @Override public void onDestroy() { super.onDestroy(); hidePDialog1(); hidePDialog2(); } private void hidePDialog1() { if (pDialog1 != null) { pDialog1.dismiss(); pDialog1 = null; } } private void hidePDialog2() { if (pDialog2 != null) { pDialog2.dismiss(); pDialog2 = null; } } }