Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mavenmusic.com;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.os.AsyncTask;
- import android.widget.TextView;
- import android.content.Context;
- import android.app.ProgressDialog;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import mavenmusic.com.data.ModelData;
- import java.util.List;
- /**
- * Created by Kuncoro on 22/03/2016.
- */
- public class MyProfileActivity extends AppCompatActivity {
- TextView txtUsername, txtNama, txtEmail, txtNomor_telp, txtAlamat, txtKodepos ;
- String id, username;
- private TextView Email,Nama, Nomor_telp, Alamat, Kodepos;
- SharedPreferences sharedpreferences;
- public static final String URL_GET_EMP = "http://192.168.1.14/mavenmusic/getdata.php?username=";
- public static final String TAG_USERNAME = "username";
- //JSON Tags
- public static final String TAG_JSON_ARRAY="result";
- public static final String TAG_EMAIL = "email";
- public static final String TAG_NAMA = "nama";
- public static final String TAG_NOMOR_TELP = "nomor_telp";
- public static final String TAG_ALAMAT = "alamat";
- public static final String TAG_KODEPOS = "kodepos";
- private String url = mavenmusic.com.util.Server.URL + "getdata.php";
- List<ModelData> mItems;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_myprofile);
- sharedpreferences = getSharedPreferences(LoginActivity.my_shared_preferences, Context.MODE_PRIVATE);
- txtUsername = (TextView) findViewById(R.id.txtUsername);
- Email = (TextView) findViewById(R.id.txtEmail);
- Nama = (TextView) findViewById(R.id.txtNama);
- Nomor_telp = (TextView) findViewById(R.id.txtNomor_telp);
- Alamat = (TextView) findViewById(R.id.txtAlamat);
- Kodepos = (TextView) findViewById(R.id.txtKodepos);
- username = sharedpreferences.getString(TAG_USERNAME, "");
- txtUsername.setText("Username : " + username);
- }
- private void getData(){
- class getData extends AsyncTask<Void,Void,String>{
- ProgressDialog loading;
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- loading = ProgressDialog.show(MyProfileActivity.this,"Fetching...",
- "Wait...",false,false);
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- loading.dismiss();
- ShowData(s);
- }
- @Override
- protected String doInBackground(Void... params) {
- RequestHandler rh = new RequestHandler();
- String s = rh.sendGetRequestParam(URL_GET_EMP,username);
- return s;
- }
- }
- getData ge = new getData();
- ge.execute();
- }
- private void ShowData(String json) {
- try {
- JSONObject JsonObject = new JSONObject(json);
- JSONArray result = JsonObject.getJSONArray(TAG_JSON_ARRAY);
- JSONObject c = result.getJSONObject(0);
- String nama = c.getString(TAG_NAMA);
- String email = c.getString(TAG_EMAIL);
- String nomor_telp = c.getString(TAG_NOMOR_TELP);
- String alamat = c.getString(TAG_ALAMAT);
- String kodepos = c.getString(TAG_KODEPOS);
- Email.setText(email);
- Nama.setText(nama);
- Nomor_telp.setText(nomor_telp);
- Alamat.setText(alamat);
- Kodepos.setText(kodepos);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement