Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.layrif.bismillah_pulang.Isi_Home;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.androidquery.AQuery;
- import com.androidquery.callback.AjaxCallback;
- import com.androidquery.callback.AjaxStatus;
- import com.layrif.bismillah_pulang.R;
- import com.squareup.picasso.Picasso;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class Dekorasi extends AppCompatActivity {
- ListView list;
- AQuery aq;
- ProgressDialog progressDialog;
- ArrayList<HashMap<String,String>> data;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_dekorasi);
- data = new ArrayList<HashMap<String, String>>();
- AmbilData();//alt enter//create method ambil data
- list = (ListView) findViewById(R.id.listdekorasi);
- }
- private void AmbilData() {
- String url = "http://192.168.100.11/wedding/dekorasi.php";
- aq = new AQuery(Dekorasi.this);
- progressDialog = new ProgressDialog(Dekorasi.this);
- progressDialog.setMessage("Loading...");
- aq.progress(progressDialog).ajax(url, String.class, new AjaxCallback<String>(){//buat {} di habis ()
- @Override
- public void callback(String url, String object, AjaxStatus status) {
- if (object != null){
- Toast.makeText(Dekorasi.this, ""+object, Toast.LENGTH_SHORT).show();
- Log.d("Respon", object);
- try{
- JSONObject json = new JSONObject(object);
- String result = json.getString("pesan");
- String sukses = json.getString("sukses");
- //jika datanya ada
- if (sukses.equalsIgnoreCase("true")){
- JSONArray jsonArray = json.getJSONArray("dekoraso");
- for (int i = 0 ; i < jsonArray.length(); i++){
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- String id_dekorasi = jsonObject.getString("id");
- String judul_dekorasi = jsonObject.getString("judul");
- String gambarnya = jsonObject.getString("gambar");
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("id", id_dekorasi);
- map.put("judul", judul_dekorasi);
- map.put("gambar", gambarnya);
- data.add(map);
- setListAdapter(data);
- }
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- });
- }
- private void setListAdapter(final ArrayList<HashMap<String, String>> data) {
- Dekorasi.CustomAdapter adapter = new Dekorasi.CustomAdapter(this, data);
- list.setAdapter(adapter);
- list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
- HashMap<String, String> map = data.get(i);
- Intent a = new Intent(getApplicationContext(), DekorasiDetail.class);
- a.putExtra("id", map.get("id"));
- startActivity(a);
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- private class CustomAdapter extends BaseAdapter {
- Activity activity;
- ArrayList<HashMap<String, String>>data2;
- LayoutInflater layoutInflater;
- public CustomAdapter(Activity activity, ArrayList<HashMap<String, String>> data2) {
- this.activity = activity;
- this.data2 = data2;
- //DONT FORGET TO chane this to data
- }
- @Override
- public int getCount() {
- return data2.size();
- }
- @Override
- public Object getItem(int i) {
- return i;
- }
- @Override
- public long getItemId(int i) {
- return i;
- }
- @Override
- public View getView(int i, View view, ViewGroup viewGroup) {
- layoutInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View v = layoutInflater.inflate(R.layout.activity_dekorasi_listitem, null);
- TextView id = (TextView)v.findViewById(R.id.iddekorasi);
- TextView jdul = (TextView)v.findViewById(R.id.juduldekorasi);
- ImageView img = (ImageView)v.findViewById(R.id.gambardekorasi);
- TextView hrg = (TextView)v.findViewById(R.id.hargadekorasi);
- TextView almt = (TextView)v.findViewById(R.id.alamatdekorasi);
- HashMap<String, String>data = new HashMap<>();
- data = data2.get(i);
- jdul.setText(data.get("judul"));
- id.setText(data.get("id"));
- String url_foto = "http://192.168.100.11/wedding/fotonya/";
- Picasso.with(Dekorasi.this).load(url_foto+data.get("gambar")).error(R.drawable.noimage).into(img);
- return v;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement