Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 760abbb

Browse filesBrowse files
JAVATECHIGJAVATECHIG
JAVATECHIG
authored and
JAVATECHIG
committed
added Android Gridview Example
added Android Gridview Example
1 parent be09dd9 commit 760abbb
Copy full SHA for 760abbb
Expand file treeCollapse file tree

34 files changed

+384
-0
lines changed
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.javatechig.gridview"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="8"
9+
android:targetSdkVersion="17" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@drawable/ic_launcher"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme" >
16+
<activity
17+
android:name="com.javatechig.gridview.MainActivity"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
Binary file not shown.

‎AndroidCustomGridView/lint.xml

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<lint>
3+
</lint>
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-14
Loading
Loading
Loading
Loading
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:drawable="@color/blue" android:state_pressed="true"/>
5+
<item android:drawable="@color/blue" android:state_selected="true"/>
6+
<item android:drawable="@color/white"/>
7+
8+
</selector>
3.98 KB
Loading
4.54 KB
Loading
6.6 KB
Loading
13.3 KB
Loading
12.3 KB
Loading
7.01 KB
Loading
12.9 KB
Loading
34.9 KB
Loading
9.56 KB
Loading
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#f0f0f0"
6+
tools:context=".MainActivity" >
7+
8+
<GridView
9+
android:id="@+id/gridView"
10+
android:layout_width="fill_parent"
11+
android:layout_height="wrap_content"
12+
android:layout_margin="5dp"
13+
android:columnWidth="100dp"
14+
android:gravity="center"
15+
android:numColumns="auto_fit"
16+
android:verticalSpacing="5dp"
17+
android:drawSelectorOnTop="true"
18+
android:stretchMode="columnWidth" >
19+
</GridView>
20+
21+
</RelativeLayout>
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="wrap_content"
4+
android:layout_height="wrap_content"
5+
android:layout_marginTop="5dp"
6+
android:orientation="vertical"
7+
android:padding="5dp"
8+
android:clickable="true"
9+
android:background="@drawable/grid_color_selector"
10+
android:focusable="true">
11+
12+
<ImageView
13+
android:id="@+id/image"
14+
android:layout_width="100dp"
15+
android:layout_height="100dp" >
16+
</ImageView>
17+
18+
<TextView
19+
android:id="@+id/text"
20+
android:layout_width="fill_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="5dp"
23+
android:gravity="center"
24+
android:textSize="12sp" >
25+
</TextView>
26+
27+
</LinearLayout>
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
2+
3+
<item
4+
android:id="@+id/action_settings"
5+
android:orderInCategory="100"
6+
android:showAsAction="never"
7+
android:title="@string/action_settings"/>
8+
9+
</menu>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw600dp devices (e.g. 7" tablets) here.
6+
-->
7+
8+
</resources>
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
6+
-->
7+
<dimen name="activity_horizontal_margin">128dp</dimen>
8+
9+
</resources>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string-array name="image_ids">
5+
<item>@drawable/image_1</item>
6+
<item>@drawable/image_2</item>
7+
<item>@drawable/image_3</item>
8+
<item>@drawable/image_4</item>
9+
<item>@drawable/image_5</item>
10+
<item>@drawable/image_6</item>
11+
<item>@drawable/image_7</item>
12+
<item>@drawable/image_8</item>
13+
<item>@drawable/image_9</item>
14+
<item>@drawable/image_1</item>
15+
<item>@drawable/image_2</item>
16+
<item>@drawable/image_3</item>
17+
<item>@drawable/image_4</item>
18+
<item>@drawable/image_5</item>
19+
<item>@drawable/image_6</item>
20+
<item>@drawable/image_7</item>
21+
<item>@drawable/image_8</item>
22+
<item>@drawable/image_9</item>
23+
</string-array>
24+
25+
</resources>
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="blue">#00abea</color>
4+
<color name="white">#ffffff</color>
5+
6+
</resources>
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">CustomGridView</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="hello_world">Hello world!</string>
7+
8+
</resources>
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.javatechig.gridview;
2+
3+
import java.util.ArrayList;
4+
import android.app.Activity;
5+
import android.content.Context;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.ArrayAdapter;
10+
import android.widget.ImageView;
11+
import android.widget.TextView;
12+
13+
/**
14+
*
15+
* @author javatechig {@link http://javatechig.com}
16+
*
17+
*/
18+
public class GridViewAdapter extends ArrayAdapter<ImageItem> {
19+
private Context context;
20+
private int layoutResourceId;
21+
private ArrayList<ImageItem> data = new ArrayList<ImageItem>();
22+
23+
public GridViewAdapter(Context context, int layoutResourceId,
24+
ArrayList<ImageItem> data) {
25+
super(context, layoutResourceId, data);
26+
this.layoutResourceId = layoutResourceId;
27+
this.context = context;
28+
this.data = data;
29+
}
30+
31+
@Override
32+
public View getView(int position, View convertView, ViewGroup parent) {
33+
View row = convertView;
34+
ViewHolder holder = null;
35+
36+
if (row == null) {
37+
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
38+
row = inflater.inflate(layoutResourceId, parent, false);
39+
holder = new ViewHolder();
40+
holder.imageTitle = (TextView) row.findViewById(R.id.text);
41+
holder.image = (ImageView) row.findViewById(R.id.image);
42+
row.setTag(holder);
43+
} else {
44+
holder = (ViewHolder) row.getTag();
45+
}
46+
47+
ImageItem item = data.get(position);
48+
holder.imageTitle.setText(item.getTitle());
49+
holder.image.setImageBitmap(item.getImage());
50+
return row;
51+
}
52+
53+
static class ViewHolder {
54+
TextView imageTitle;
55+
ImageView image;
56+
}
57+
}
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.javatechig.gridview;
2+
3+
import android.graphics.Bitmap;
4+
5+
/**
6+
* @author javatechig {@link http://javatechig.com}
7+
*
8+
*/
9+
public class ImageItem {
10+
private Bitmap image;
11+
private String title;
12+
13+
public ImageItem(Bitmap image, String title) {
14+
super();
15+
this.image = image;
16+
this.title = title;
17+
}
18+
19+
public Bitmap getImage() {
20+
return image;
21+
}
22+
23+
public void setImage(Bitmap image) {
24+
this.image = image;
25+
}
26+
27+
public String getTitle() {
28+
return title;
29+
}
30+
31+
public void setTitle(String title) {
32+
this.title = title;
33+
}
34+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.