Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. @Override
  2. public void onClick(View v) {
  3.  
  4.  
  5. // findViewbyId coba pakai butterknife
  6. //kenap gagal, karena ketika klik pertama belum dapet return dari server
  7. //klik kedua berhasil Karena sudah dapet return
  8. // volley itu asycrounous silakan googling
  9.  
  10. EditText jb = (EditText) findViewById(R.id.jawaban);//
  11. final String gjb = jb.getText().toString();
  12. final TextView tv = (TextView) findViewById(R.id.get_jawab);
  13. final String tvv = tv.getText().toString();
  14. tv.setText("");
  15.  
  16. StringRequest stringRequest = new StringRequest(Request.Method.GET, URLs.URL_GET_VERIFIKASI, new Response.Listener<String>() {
  17. @Override
  18. public void onResponse(String response) {
  19. //response api Nya bentuk nya bagaimana ?
  20. //
  21. try {
  22. JSONObject jsonObject = new JSONObject(response);
  23. JSONArray jsonArray = jsonObject.getJSONArray("verifikasi");
  24. for (int i = 0; i < jsonArray.length(); i++) {
  25. JSONObject jo = jsonArray.getJSONObject(i);
  26. // Do you fancy stuff
  27. String j= jo.getString("jawab");
  28. tv.append(j);
  29. }
  30. } catch (JSONException e) {
  31. e.printStackTrace();
  32. }
  33. //validasi pindahin kesini Aja
  34. }
  35. }, new Response.ErrorListener() {
  36. @Override
  37. public void onErrorResponse(VolleyError error) {
  38. }
  39. });
  40. RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
  41. requestQueue.add(stringRequest);
  42. //proses validasi di pindahin ke on resspone aja
  43. if (gjb.equals(tvv)){
  44. registerUser();
  45. }else {
  46. AlertDialog.Builder vm = new AlertDialog.Builder(MainActivity.this);
  47. vm.setTitle("KESALAHAN ! ");
  48. vm.setMessage("Kode Verifikasi Tidak Tepat, Silahkan Hubungi Admin Untuk Bantuan! ");
  49. vm.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
  50. public void onClick(DialogInterface arg0, int arg1) {
  51. }
  52. });
  53. // show it
  54. vm.show();
  55. }
  56. return;
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement