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; } } } 
  • one
    What is your problem? you can not hang up requests for pressing the button, make the requests themselves, do not understand how to use the library, are you too lazy to write yourself or what? To get a useful answer, you need to at least attach the code, as you have already tried to solve your problem yourself and put your difficulties in more detail - pavlofff
  • I want to get a minimal code. I will apply the code to the question - Ilya Nenilin

1 answer 1

Make 3 different requests, 3 different buttons or activate. Or create a holder, then it will be possible to do it in 1 activation, but I would recommend to make 3 different activations, so it will be easier