Grid Views - Hallo sahabat Google Android Developer Tutorial, Pada Artikel yang anda baca kali ini dengan judul Grid Views, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.
Judul : Grid Views
link : Grid Views
4.No need to modify Androidmanifest.xml
Anda sekarang membaca artikel Grid Views dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/grid-views.html
Judul : Grid Views
link : Grid Views
Grid Views
GRIDVIEW Tutorial
The GridView view shows items in two-dimensional scrolling grid. You can use the GridView view together with ImageView views to display a series of images.
1.Create Project names ,package name,Activity and layout xml as listed in table below
1.Create Project names ,package name,Activity and layout xml as listed in table below
Property name | Property value |
Project name | SRM_GridViewTutorial |
Package name | in.ac.srmuniv.gridviewtutorial |
Activity name | MainActivity |
Layout xml name | activity_main |
2.Copy the code to the file activity_main.xml in res/layout folder
<?xml version="1.0"encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
3.Copy the code in MainActivity.java. Activity.
package in.ac.srmuniv.gridviewtutorial;
importandroid.app.Activity;
importandroid.content.Context;
import android.os.Bundle;
import android.view.View;
importandroid.view.ViewGroup;
import android.widget.AdapterView;
importandroid.widget.BaseAdapter;
importandroid.widget.GridView;
importandroid.widget.ImageView;
importandroid.widget.Toast;
importandroid.widget.AdapterView.OnItemClickListener;
3.Copy the code in MainActivity.java. Activity.
package in.ac.srmuniv.gridviewtutorial;
importandroid.app.Activity;
importandroid.content.Context;
import android.os.Bundle;
import android.view.View;
importandroid.view.ViewGroup;
import android.widget.AdapterView;
importandroid.widget.BaseAdapter;
importandroid.widget.GridView;
importandroid.widget.ImageView;
importandroid.widget.Toast;
importandroid.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity
{
// ---the images to display---
Integer[] imageIDs = {
R.drawable.srm1,
R.drawable.srm2,
R.drawable.srm3,
R.drawable.srm4,
R.drawable.srm5,
R.drawable.srm6,
R.drawable.srm7
};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
GridView gridView = (GridView)
findViewById(R.id.activity_main);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new
OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position,
long id)
{
Toast.makeText(getBaseContext(),
"srm" + (position + 1) + "selected",
Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
public ImageAdapter(Context c)
{
context = c;
}
// ---returns the number of images---
public int getCount() {
return imageIDs.length;
}
// ---returns the ID of an item---
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
// ---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(context);
imageView.setLayoutParams(newGridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(5, 5, 5, 5);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(imageIDs[position]);
return imageView;
}
}
}4.No need to modify Androidmanifest.xml
5.Run the application in the emulator. Figure 1 shows the GridView view in action.
Demikianlah Artikel Grid Views
Sekianlah artikel Grid Views kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Grid Views dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/grid-views.html
Grid Views
4/
5
Oleh
Unknown