Created
February 7, 2017 11:56
-
-
Save alfianyusufabdullah/272c772f8ddfb6819762f317ec14b8a1 to your computer and use it in GitHub Desktop.
Tutorial GridView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jonesrandom.tutorialgridview; | |
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.GridView; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
/// VARIBEL DATA BERUPA ARRAY YANG AKAN DI TAMPILKAN KEDALAM GRIDVIEW | |
String[] data = { | |
"Gorontalo", | |
"Gorontalo Utara", | |
"Boalemo", | |
"Pohuawato", | |
"Bone Bolango", | |
"Limboto"}; | |
/// VARIABEL GRIDVIEW | |
GridView gView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// MEMBUAT ARRAYADAPTER | |
ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data); | |
/// INISIALISALI GRIDVIEW DENGAN VIEW | |
gView = (GridView) findViewById(R.id.listGrid); | |
/// SET ADAPTER KEDALAM GRIDVIEW | |
gView.setAdapter(adp); | |
/// MENAMBAH ACTION SAAT ITEM LIST DIKLIK | |
gView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> adapterView, View view, int posisi, long l) { | |
String Text = data[posisi]; | |
Toast.makeText(MainActivity.this , Text , Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment