Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.asusx441n.examplelistviewdinamis;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ListView;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.concurrent.ExecutionException;
- public class MainActivity extends AppCompatActivity {
- private ArrayList<HashMap<String, String>> data = null;
- HashMap<String, String> order;
- Global global = new Global();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- showAllData();
- ListView ceritarakyat = (ListView) findViewById(R.id.am_lv_cerita_rakyat);
- ceritarakyat.setOnItemClickListener(onItemClickListener);
- }
- public void showAllData(){
- data = new ArrayList<HashMap<String, String>>();
- try {
- ServiceAll members = new ServiceAll(MainActivity.this);
- data = members.execute().get();
- Log.e("isExist", String.valueOf(data));
- } catch (ExecutionException ex) {
- // Toast.makeText(getActivity(), "Error EX" + ex.toString(),Toast.LENGTH_SHORT).show();
- } catch (InterruptedException ei) {
- //Toast.makeText(getActivity(), "Error EI" + ei.toString(),Toast.LENGTH_SHORT).show();
- }
- }
- public AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
- final HashMap<String, String> hashMap = ((AdapterListView) parent.getAdapter()).getItemDisvisitoril(position);
- Intent i = new Intent(MainActivity.this, MainActivityDetail.class);
- i.putExtra(global.DATA_TITLE,hashMap.get(global.DATA_TITLE));
- i.putExtra(global.DATA_PROVINSI,hashMap.get(global.DATA_PROVINSI));
- i.putExtra(global.DATA_IMAGE2,hashMap.get(global.DATA_IMAGE2));
- i.putExtra(global.DATA_CONTENT,hashMap.get(global.DATA_CONTENT));
- i.putExtra(global.DATA_AUTHOR,hashMap.get(global.DATA_AUTHOR));
- i.putExtra(global.DATA_OUTCOME,hashMap.get(global.DATA_OUTCOME));
- startActivity(i);
- }
- };
- @Override
- public void onBackPressed() {
- new AlertDialog.Builder(this)
- .setMessage("Are you sure you want to exit?")
- .setCancelable(false)
- .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- finish();
- }
- })
- .setNegativeButton("No", null)
- .show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement