如何在我的画廊文件夹? [英] how to create folders in my gallery?
问题描述
您好我已创建了一个画廊申请其工作正常...如果我运行库显示所有SD卡图片...但我如何从照片的特定文件夹?我是否需要更改查询?例如:墙纸,图片,卡马拉,专辑............
我的源$ C $ C:
包image.Thumbnails;进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;
进口android.database.Cursor;
进口android.net.Uri;
进口android.os.Bundle;
进口android.provider.MediaStore;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.AdapterView;
进口android.widget.BaseAdapter;
进口android.widget.GridView;
进口android.widget.ImageView;
进口android.widget.AdapterView.OnItemClickListener;公共类ImageThumbnailsActivity延伸活动{
/ **当第一次创建活动调用。 * /
私人光标imagecursor,actualimagecursor;
私人诠释image_column_index,actual_image_column_index;
GridView控件imagegrid;
私人诠释计数;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
init_phone_image_grid();
}
私人无效init_phone_image_grid(){
的String [] = IMG {MediaStore.Images.Thumbnails._ID};
imagecursor = managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,IMG,空,
空,MediaStore.Images.Thumbnails.IMAGE_ID +);
image_column_index = imagecursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
数= imagecursor.getCount();
imagegrid =(GridView控件)findViewById(R.id.PhoneImageGrid);
imagegrid.setAdapter(新ImageAdapter(getApplicationContext()));
imagegrid.setOnItemClickListener(新OnItemClickListener(){
公共无效onItemClick(适配器视图父母,视图V,
INT位置,长的id){
System.gc()的;
的String [] = PROJ {MediaStore.Images.Media.DATA};
actualimagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,PROJ,
NULL,NULL,NULL);
actual_image_column_index = actualimagecursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToPosition(位置);
串I = actualimagecursor.getString(actual_image_column_index);
System.gc()的;
意向意图=新意图(getApplicationContext()
ViewImage.class);
intent.putExtra(文件名,我);
startActivity(意向);
}
});
}
公共类ImageAdapter延伸BaseAdapter {
私人语境mContext;
公共ImageAdapter(上下文C){
mContext = C;
}
公众诠释的getCount(){
返回计数;
}
公共对象的getItem(INT位置){
返回的位置;
}
众长getItemId(INT位置){
返回的位置;
}
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
System.gc()的;
ImageView的I =新ImageView的(mContext.getApplicationContext());
如果(convertView == NULL){
imagecursor.moveToPosition(位置);
INT ID = imagecursor.getInt(image_column_index);
i.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
+ ID));
i.setScaleType(ImageView.ScaleType.CENTER_CROP);
i.setLayoutParams(新GridView.LayoutParams(92,92));
}
其他{
I =(ImageView的)convertView;
}
返回我;
}
}
}
拉尼,
下面是一个链接到源$ C $ C为Android图库应用:的 http://android.git.kernel.org/?p=platform/packages/apps/Gallery3D.git;a=tree
您可以使用此作为一个例子,或为您的应用程序的起点。祝你好运!
Hi I have created one gallery application its working fine...if i run the gallery display all sdcard images...but How do I get pictures from a specific folder? Do I need to change the query? Example: wallpapers, images, camara, album............
My source code:
package image.Thumbnails;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class ImageThumbnailsActivity extends Activity {
/** Called when the activity is first created. */
private Cursor imagecursor, actualimagecursor;
private int image_column_index, actual_image_column_index;
GridView imagegrid;
private int count;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init_phone_image_grid();
}
private void init_phone_image_grid() {
String[] img = { MediaStore.Images.Thumbnails._ID };
imagecursor = managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, img, null,
null, MediaStore.Images.Thumbnails.IMAGE_ID + "");
image_column_index = imagecursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
count = imagecursor.getCount();
imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
imagegrid.setAdapter(new ImageAdapter(getApplicationContext()));
imagegrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v,
int position, long id) {
System.gc();
String[] proj = { MediaStore.Images.Media.DATA };
actualimagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
null, null, null);
actual_image_column_index = actualimagecursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToPosition(position);
String i = actualimagecursor.getString(actual_image_column_index);
System.gc();
Intent intent = new Intent(getApplicationContext(),
ViewImage.class);
intent.putExtra("filename", i);
startActivity(intent);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position,View convertView,ViewGroup parent) {
System.gc();
ImageView i = new ImageView(mContext.getApplicationContext());
if (convertView == null) {
imagecursor.moveToPosition(position);
int id = imagecursor.getInt(image_column_index);
i.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""
+ id));
i.setScaleType(ImageView.ScaleType.CENTER_CROP);
i.setLayoutParams(new GridView.LayoutParams(92, 92));
}
else {
i = (ImageView) convertView;
}
return i;
}
}
}
Rani,
Here is a link to the source code for the Android Gallery app: http://android.git.kernel.org/?p=platform/packages/apps/Gallery3D.git;a=tree
You can use this as an example or a starting point for your app. Good luck!
这篇关于如何在我的画廊文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!