コード例 #1
0
ファイル: EditProfile.java プロジェクト: codelicius/jodi
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_profile);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    db = new SQLiteController(getApplicationContext());
    sessions = new sessionmanager(getApplicationContext());

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) fromActivity = bundle.getString("fromActivity");

    HashMap<String, String> profile = db.getUserDetails();
    String id = profile.get("id");
    String gender = profile.get("gender");
    String age = profile.get("age");
    String race = profile.get("race");
    String religion = profile.get("religion");
    String height = profile.get("height");
    String location = profile.get("location");
    String horoscope = profile.get("horoscope");
    String job = profile.get("job");
    String userDetail = profile.get("user_detail");
    String roko = profile.get("merokok");
    String alkohol = profile.get("alkohol");
    String tps = profile.get("tipe_pasangan");
    String kgt = profile.get("kegiatan");
    String interest = profile.get("interest");
    String satnite = profile.get("satnite");

    deskripsi = (EditText) findViewById(R.id.deskripsi);
    tipe_pasangan = (EditText) findViewById(R.id.tipe_pasangan);
    kegiatan = (EditText) findViewById(R.id.kegiatan);
    halsuka = (EditText) findViewById(R.id.halsuka);
    malming = (EditText) findViewById(R.id.malming);
    tinggi = (EditText) findViewById(R.id.tinggi);
    txtReligion = (Spinner) findViewById(R.id.agama);
    txtRokok = (Spinner) findViewById(R.id.merokok);
    txtAlkohol = (Spinner) findViewById(R.id.alkohol);
    txtRace = (Spinner) findViewById(R.id.suku);
    txtLocation = (Spinner) findViewById(R.id.lokasi);
    txtHoroscope = (Spinner) findViewById(R.id.horoskop);
    txtJob = (Spinner) findViewById(R.id.pekerjaan);
    getSpinner("suku");
    getSpinner("pekerjaan");
    getSpinner("lokasi");
    tinggi.setText(height);
    deskripsi.setText(userDetail);
    tipe_pasangan.setText(tps);
    kegiatan.setText(kgt);
    halsuka.setText(interest);
    malming.setText(satnite);
    getIndex(txtRokok, roko);
    getIndex(txtAlkohol, alkohol);
    getIndex(txtRace, race);
    getIndex(txtLocation, location);
    getIndex(txtHoroscope, horoscope);
    getIndex(txtJob, job);
    getIndex(txtReligion, religion);
  }
コード例 #2
0
ファイル: EditProfile.java プロジェクト: codelicius/jodi
  public void getSpinner(String spin) {
    final HashMap<String, String> profile = db.getUserDetails();
    String API = AppConfig.urlAPI;
    String url = API + "?jodiSpinner";

    final ArrayList<String> pekerjaan = new ArrayList<String>();
    final ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, pekerjaan);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final ArrayList<String> lokasi = new ArrayList<String>();
    final ArrayAdapter<String> adapters =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lokasi);
    adapters.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final ArrayList<String> suku = new ArrayList<String>();
    final ArrayAdapter<String> adapterSuku =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, suku);
    adapterSuku.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    JsonObjectRequest jsonRequest =
        new JsonObjectRequest(
            Request.Method.GET,
            url,
            null,
            new Response.Listener<JSONObject>() {
              @Override
              public void onResponse(JSONObject response) {
                Log.d("respon", response.toString());
                try {
                  JSONArray pk = response.getJSONArray("Pekerjaan");
                  JSONArray lk = response.getJSONArray("Lokasi");
                  JSONArray sk = response.getJSONArray("Suku");

                  if (profile.get("job") != null) pekerjaan.add(profile.get("job"));
                  if (profile.get("location") != null) lokasi.add(profile.get("location"));
                  if (profile.get("suku") != null) suku.add(profile.get("suku"));

                  for (int i = 0; i < pk.length(); i++) {
                    pekerjaan.add(pk.getString(i));
                  }

                  for (int i = 0; i < lk.length(); i++) {
                    lokasi.add(lk.getString(i));
                  }

                  for (int i = 0; i < sk.length(); i++) {
                    suku.add(sk.getString(i));
                  }

                  adapters.notifyDataSetChanged();
                  adapter.notifyDataSetChanged();
                  adapterSuku.notifyDataSetChanged();
                  Log.d("array pekerjaan", pekerjaan.toString());
                } catch (JSONException e) {
                  e.printStackTrace();
                }
                // the response is already constructed as a JSONObject!

              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                Toast.makeText(
                    getApplicationContext(), "silakan cek koneksi anda", Toast.LENGTH_LONG);
                error.printStackTrace();
              }
            });

    // Adding request to request queue
    Volley.newRequestQueue(this).add(jsonRequest);
    jsonRequest.setRetryPolicy(
        new DefaultRetryPolicy(
            60000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    if (spin.equals("pekerjaan")) txtJob.setAdapter(adapter);
    else if (spin.equals("lokasi")) txtLocation.setAdapter(adapters);
    else txtRace.setAdapter(adapterSuku);
  }