Advertisement
euis_kusesa

MainActivity.java

Dec 24th, 2018
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.02 KB | None | 0 0
  1. package com.example.asusx441n.examplelistviewdinamis;
  2.  
  3. import android.content.DialogInterface;
  4. import android.content.Intent;
  5. import android.support.v7.app.AlertDialog;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.AdapterView;
  11. import android.widget.ListView;
  12.  
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. import java.util.concurrent.ExecutionException;
  16.  
  17. public class MainActivity extends AppCompatActivity {
  18.  
  19.     private ArrayList<HashMap<String, String>> data = null;
  20.  
  21.     HashMap<String, String> order;
  22.     Global global = new Global();
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_main);
  28.  
  29.         showAllData();
  30.  
  31.         ListView ceritarakyat = (ListView) findViewById(R.id.am_lv_cerita_rakyat);
  32.  
  33.         ceritarakyat.setOnItemClickListener(onItemClickListener);
  34.  
  35.     }
  36.     public void showAllData(){
  37.  
  38.         data = new ArrayList<HashMap<String, String>>();
  39.  
  40.         try {
  41.             ServiceAll members = new ServiceAll(MainActivity.this);
  42.  
  43.             data = members.execute().get();
  44.  
  45.             Log.e("isExist", String.valueOf(data));
  46.  
  47.         } catch (ExecutionException ex) {
  48.             // Toast.makeText(getActivity(), "Error EX" + ex.toString(),Toast.LENGTH_SHORT).show();
  49.         } catch (InterruptedException ei) {
  50.             //Toast.makeText(getActivity(), "Error EI" + ei.toString(),Toast.LENGTH_SHORT).show();
  51.         }
  52.  
  53.     }
  54.  
  55.     public AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
  56.  
  57.         @Override
  58.         public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
  59.             final HashMap<String, String> hashMap = ((AdapterListView) parent.getAdapter()).getItemDisvisitoril(position);
  60.  
  61.             Intent i = new Intent(MainActivity.this, MainActivityDetail.class);
  62.  
  63.  
  64.             i.putExtra(global.DATA_TITLE,hashMap.get(global.DATA_TITLE));
  65.             i.putExtra(global.DATA_PROVINSI,hashMap.get(global.DATA_PROVINSI));
  66.             i.putExtra(global.DATA_IMAGE2,hashMap.get(global.DATA_IMAGE2));
  67.             i.putExtra(global.DATA_CONTENT,hashMap.get(global.DATA_CONTENT));
  68.             i.putExtra(global.DATA_AUTHOR,hashMap.get(global.DATA_AUTHOR));
  69.             i.putExtra(global.DATA_OUTCOME,hashMap.get(global.DATA_OUTCOME));
  70.  
  71.  
  72.             startActivity(i);
  73.         }
  74.  
  75.     };
  76.  
  77.     @Override
  78.     public void onBackPressed() {
  79.         new AlertDialog.Builder(this)
  80.                 .setMessage("Are you sure you want to exit?")
  81.                 .setCancelable(false)
  82.                 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  83.                     public void onClick(DialogInterface dialog, int id) {
  84.  
  85.                         finish();
  86.                     }
  87.                 })
  88.                 .setNegativeButton("No", null)
  89.                 .show();
  90.  
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement