1
私はプログラムを実行しましたsdcard
からのすべてのイメージを動的に表示しました。しかし今、私はsdcard
からすべての画像を表示する代わりに、単一の画像を動的に表示したいと考えています。どのようにsdcardから単一のイメージを動的に表示する
public class Gallery1Activity extends Activity {
// private ArrayList<String> imglist;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
ArrayList arr = new ArrayList();
super.onCreate(savedInstanceState);
setContentView(R.layout.gallerygrid);
GridView gv1=(GridView) this.findViewById(R.id.gridView1);
//gv1.setAdapter(new galleryImageAdapter(this));
arr = galldatabase();
gv1.setAdapter(new galleryImageAdapter(this,arr));
}
private ArrayList galldatabase() {
// TODO Auto-generated method stub
ArrayList ThumbsIDList = new ArrayList();
//Uri u=MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
/*String[] projection =new String[]{
Images.Thumbnails._ID,
Images.Thumbnails.DATA,
Images.Thumbnails.IMAGE_ID};*/
Cursor galleryimagecursor=managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,new String[]{
Images.Thumbnails._ID,
Images.Thumbnails.DATA} , null, null, null);
if(galleryimagecursor!=null&&galleryimagecursor.moveToFirst()){
String thumbsID;
String thumbsImageID;
String thumbsData;
int num=0;
do{
thumbsID=galleryimagecursor.getString(galleryimagecursor.getColumnIndexOrThrow(Images.Thumbnails._ID));
thumbsData=galleryimagecursor.getString(galleryimagecursor.getColumnIndexOrThrow(Images.Thumbnails.DATA));
Log.i("BMP","size "+thumbsID+" "+thumbsData);
num++;
/*if(thumbsImageID!= null) {*/
ThumbsIDList.add(thumbsID);
/*ThumbsImageIDList.add(galleryimagecursor.getString(thumbsImageIDcol));
ThumbsDataList.add(galleryimagecursor.getString(thumbsDataCol));
}*/
}
while(galleryimagecursor.moveToNext());
}
return ThumbsIDList;
}
}
は、アダプタのコードは次の次のように 私のコーディングがある
public class galleryImageAdapter extends BaseAdapter {
Context con;
private ArrayList<String> imgList;
private String thumbsID;
public galleryImageAdapter(Context c,ArrayList arr){
con=c;
imgList = arr;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return imgList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v;
if(convertView==null){
LayoutInflater li;
li = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=li.inflate(R.layout.galleryadapter,null);
final ImageView iv1=(ImageView)v.findViewById(R.id.galimage);
TextView tv1=(TextView)v.findViewById(R.id.galimagtext);
tv1.setText("Image"+position);
Log.d("imagevalue",imgList.get(position));
iv1.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+imgList.get(position)/*galleryimagecursor.getColumnIndexOrThrow(Images.Thumbnails._ID)*//*imgList.get(position)*/));
}
else
v=convertView;
return v;
}
}