Advertisement
egantara

Untitled

Jan 16th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. package mavenmusic.com;
  2.  
  3.  
  4. import android.content.SharedPreferences;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.AsyncTask;
  8. import android.widget.TextView;
  9. import android.content.Context;
  10. import android.app.ProgressDialog;
  11. import org.json.JSONArray;
  12. import org.json.JSONException;
  13. import org.json.JSONObject;
  14. import mavenmusic.com.data.ModelData;
  15. import java.util.List;
  16.  
  17. /**
  18. * Created by Kuncoro on 22/03/2016.
  19. */
  20. public class MyProfileActivity extends AppCompatActivity {
  21.  
  22. TextView txtUsername, txtNama, txtEmail, txtNomor_telp, txtAlamat, txtKodepos ;
  23. String id, username;
  24.  
  25. private TextView Email,Nama, Nomor_telp, Alamat, Kodepos;
  26. SharedPreferences sharedpreferences;
  27. public static final String URL_GET_EMP = "http://192.168.1.14/mavenmusic/getdata.php?username=";
  28. public static final String TAG_USERNAME = "username";
  29.  
  30. //JSON Tags
  31. public static final String TAG_JSON_ARRAY="result";
  32. public static final String TAG_EMAIL = "email";
  33. public static final String TAG_NAMA = "nama";
  34. public static final String TAG_NOMOR_TELP = "nomor_telp";
  35. public static final String TAG_ALAMAT = "alamat";
  36. public static final String TAG_KODEPOS = "kodepos";
  37.  
  38.  
  39.  
  40. private String url = mavenmusic.com.util.Server.URL + "getdata.php";
  41. List<ModelData> mItems;
  42.  
  43. @Override
  44. protected void onCreate(Bundle savedInstanceState) {
  45. super.onCreate(savedInstanceState);
  46. setContentView(R.layout.activity_myprofile);
  47. sharedpreferences = getSharedPreferences(LoginActivity.my_shared_preferences, Context.MODE_PRIVATE);
  48.  
  49.  
  50. txtUsername = (TextView) findViewById(R.id.txtUsername);
  51. Email = (TextView) findViewById(R.id.txtEmail);
  52. Nama = (TextView) findViewById(R.id.txtNama);
  53. Nomor_telp = (TextView) findViewById(R.id.txtNomor_telp);
  54. Alamat = (TextView) findViewById(R.id.txtAlamat);
  55. Kodepos = (TextView) findViewById(R.id.txtKodepos);
  56.  
  57.  
  58. username = sharedpreferences.getString(TAG_USERNAME, "");
  59. txtUsername.setText("Username : " + username);
  60. }
  61. private void getData(){
  62. class getData extends AsyncTask<Void,Void,String>{
  63. ProgressDialog loading;
  64. @Override
  65. protected void onPreExecute() {
  66. super.onPreExecute();
  67.  
  68. loading = ProgressDialog.show(MyProfileActivity.this,"Fetching...",
  69. "Wait...",false,false);
  70. }
  71.  
  72. @Override
  73. protected void onPostExecute(String s) {
  74. super.onPostExecute(s);
  75.  
  76. loading.dismiss();
  77. ShowData(s);
  78. }
  79.  
  80. @Override
  81. protected String doInBackground(Void... params) {
  82. RequestHandler rh = new RequestHandler();
  83. String s = rh.sendGetRequestParam(URL_GET_EMP,username);
  84. return s;
  85. }
  86. }
  87. getData ge = new getData();
  88. ge.execute();
  89. }
  90.  
  91.  
  92. private void ShowData(String json) {
  93.  
  94. try {
  95. JSONObject JsonObject = new JSONObject(json);
  96. JSONArray result = JsonObject.getJSONArray(TAG_JSON_ARRAY);
  97. JSONObject c = result.getJSONObject(0);
  98. String nama = c.getString(TAG_NAMA);
  99. String email = c.getString(TAG_EMAIL);
  100. String nomor_telp = c.getString(TAG_NOMOR_TELP);
  101. String alamat = c.getString(TAG_ALAMAT);
  102. String kodepos = c.getString(TAG_KODEPOS);
  103.  
  104. Email.setText(email);
  105. Nama.setText(nama);
  106. Nomor_telp.setText(nomor_telp);
  107. Alamat.setText(alamat);
  108. Kodepos.setText(kodepos);
  109.  
  110. } catch (JSONException e) {
  111. e.printStackTrace();
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement