Professional Documents
Culture Documents
1 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
Rp82.400
Rp356.300
Rp415.200
Rp403.800
Rp168.200
Rp35.200
11/8/2016 7:56 PM
2 of 12
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
package ganti.dengan.nama.packagemu;
import
import
import
import
import
import
android.content.Context;
android.view.View;
android.view.ViewGroup;
android.widget.BaseAdapter;
android.widget.GridView;
android.widget.ImageView;
11/8/2016 7:56 PM
3 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
68
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ganti.dengan.nama.packagemu;
01
02
03
04
05
06
07
08
09
import
import
import
import
import
import
import
import
import
android.os.Bundle;
android.app.Activity;
android.content.Intent;
android.view.View;
android.view.View.OnClickListener;
android.widget.AdapterView;
android.widget.AdapterView.OnItemClickListener;
android.widget.GridView;
android.widget.Toast;
<ImageView
android:id="@+id/singleimage"
android:layout_width="wrap_content"
11/8/2016 7:56 PM
4 of 12
10
11
12
13
14
15
16
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
android:layout_height="0dip"
android:contentDescription="gambar tunggal"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/>
</LinearLayout>
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
package ganti.dengan.nama.packagemu
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="id.sg.apollo.sg"
android:versionCode="1"
android:versionName="1.0" >
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class SingleImage extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.singleimage);
int imId = this.getIntent().getExtras().getInt("posisi");
ImageView iv = (ImageView) findViewById(R.id.singleimage);
int image = ImageAdapter.mThumbIds[imId];
iv.setImageResource(image);
}
}
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SingleImage"
android:label="@string/app_name"
>
</activity>
</application>
</manifest>
11/8/2016 7:56 PM
5 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
11/8/2016 7:56 PM
6 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
Belajar Membuat
TabLayout di Android...
Belajar Membuat...
11/8/2016 7:56 PM
7 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
1
2
3
4
5
6
7
8
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tiga);
GridView gridView = (GridView) findViewById(R.id.gridview_followed);
gridView.setAdapter(new ImageAdapter (this));
gridView.setOnItemClickListener(this);
}
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
11/8/2016 7:56 PM
8 of 12
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
}
imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
Bitmap bm = decodeSampledBitmapFromUri(itemList.get(position), 300, 300);
imageView.setImageBitmap(bm);
return imageView;
}
public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, int reqHeight) {
Bitmap bm = null;
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(path, options);
return bm;
}
public int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height / (float)reqHeight);
} else {
inSampleSize = Math.round((float)width / (float)reqWidth);
}
}
return inSampleSize;
}
}
ImageAdapter myImageAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_camera);
GridView gridview = (GridView) findViewById(R.id.gridview);
myImageAdapter = new ImageAdapter(this);
gridview.setAdapter(myImageAdapter);
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory()
.getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/Pictures/ePublisher/";
Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("IMG");
}
});
for (File file : files){
myImageAdapter.add(file.getAbsolutePath());
}
gridview.setOnItemClickListener(this);
}
11/8/2016 7:56 PM
9 of 12
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
@Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(getBaseContext(), "Photo "+(position+1)+
" selected", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, viewImage.class);
Bundle b = new Bundle();
b.putInt("posisi", position);
i.putExtras(b);
startActivity(i);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
11/8/2016 7:56 PM
10 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em>
<i> <q cite=""> <s> <strike> <strong>
11/8/2016 7:56 PM
11 of 12
Follow @twoh
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
691 followers
11/8/2016 7:56 PM
12 of 12
http://www.twoh.co/2013/04/tutorial-android-membuat-image-gallery-gal...
11/8/2016 7:56 PM