Berikut Source Codenya :
Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="35dp"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="35dp"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</LinearLayout>
GridViewActivity.java
package com.jajal.gridview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
public class GridViewActivity extends Activity implements OnItemClickListener{
static final String[] TEAMWORK = new String[] { "Berikut Nama2 Kelompok Kami :", "Akbar Seto Ramadhan (A11.2011.05937)", "Galuh Adjeng Sekarsari (A11.2011.05996)", "Izzi Abdul Salam S (A11.2011.05832)",
"M. Chair Ziaulahq (A11.2011.06280)", "Muhammad Risman N (A11.2011.06152)"};
TextView text;
GridView grid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
grid = (GridView)findViewById(R.id.grid);
text = (TextView)findViewById(R.id.text);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, TEAMWORK);
grid.setAdapter(arrayAdapter);
grid.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
text.setText("Bagian yang dipilih adalah " + parent.getItemAtPosition(pos).toString());
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
public class GridViewActivity extends Activity implements OnItemClickListener{
static final String[] TEAMWORK = new String[] { "Berikut Nama2 Kelompok Kami :", "Akbar Seto Ramadhan (A11.2011.05937)", "Galuh Adjeng Sekarsari (A11.2011.05996)", "Izzi Abdul Salam S (A11.2011.05832)",
"M. Chair Ziaulahq (A11.2011.06280)", "Muhammad Risman N (A11.2011.06152)"};
TextView text;
GridView grid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
grid = (GridView)findViewById(R.id.grid);
text = (TextView)findViewById(R.id.text);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, TEAMWORK);
grid.setAdapter(arrayAdapter);
grid.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
text.setText("Bagian yang dipilih adalah " + parent.getItemAtPosition(pos).toString());
}
}
Berikut Hasil dari Aplikasinya:
Yaitu apabila kita klik salah satu nama didalam kota akan muncul tampilannya yang berada di atas nama-nama tersebut.
Tidak ada komentar:
Posting Komentar