Skip to content

Instantly share code, notes, and snippets.

@alfianyusufabdullah
Last active February 3, 2017 11:13
Show Gist options
  • Save alfianyusufabdullah/69302d87e76936af22b32eeb3d72075b to your computer and use it in GitHub Desktop.
Save alfianyusufabdullah/69302d87e76936af22b32eeb3d72075b to your computer and use it in GitHub Desktop.
package com.jonesrandom.tutoriallistview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
/// VARIABEL LISTVIEW
ListView listDaerah;
List<ModelDaerah> listData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/// INISIALISASI DATA YANG AKAN DI TAMPILKAN KE LISTVIEW
listData = new ArrayList<ModelDaerah>();
listData.add(new ModelDaerah("Kota Gorontalo", "Kota Gorontalo", R.drawable.logo_kota_gorontalo));
listData.add(new ModelDaerah("Kabupaten Gorontalo", "Limboto", R.drawable.logo_kab_gorontalo));
listData.add(new ModelDaerah("Kabupaten Gorontalo Utara", "Kwandang", R.drawable.logo_kab_gorut));
listData.add(new ModelDaerah("Kabupaten Boalemo", "Tilamuta", R.drawable.logo_kab_boalemo));
listData.add(new ModelDaerah("Kabupaten Bone Bolango", "Suwawa", R.drawable.logo_bone_bolango));
listData.add(new ModelDaerah("Kabupaten Pohuwato", "Marisa", R.drawable.logo_kab_pohuwato));
/// MEMBUAT ADAPTER
ListviewAdapter Adapter = new ListviewAdapter(this, R.layout.row_listview , listData);
/// INISAILISASI LISTVIEW
listDaerah = (ListView) findViewById(R.id.listView);
/// SET ADAPTER LISTVIEW
listDaerah.setAdapter(Adapter);
/// MENAMBAH ACTION SAAT ITEM DI KLIK
listDaerah.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int posisi, long l) {
/// MENGIRIM DATA KE ACTIVITY DETAIL
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment