0
I have images inside the drawable
and to access it simply R.drawable.myimage
.
How to store this image in a vetor
?
0
I have images inside the drawable
and to access it simply R.drawable.myimage
.
How to store this image in a vetor
?
2
Don’t keep the pictures, keep your Resource Id using a int[]
:
int[] imagensIds = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3
};
You can pass all images to a method:
processaImagens(imagensIds);
or just a:
processaImagem(imagensIds[1]);
State the methods as follows:
private processaImagens(int[] imagensIds){
}
private processaImagem(int imagemId){
}
+1 I believe this is the best way.
@Diegof I still waited for you to answer.
To tell you the truth I hadn’t even come up with anything to answer, the suggestion was kind of automatic when I saw the question. :/
@ramaral it is possible to place the resource Id
in a notepad or arquivo.txt
make this file read and store in an integer array? if yes how?
Yes it is possible. A resource Id
is no more than an integer. You can use Sharedpreferences for this.
As you know we should not use comments to ask and answer new questions:)
@ramaral beauty I will open a new question
-2
as this answer is long without complement goes there: ///I create a Gallery Gallery gallery1;
//declares an array of images already pasted into Drawable to be pic0....: Integer[] imagensID = { R.drawable.pic0, R.drawable.pic1, R.drawable.pic2, R.drawable.pic3 }; on onCreate I start and do the logica to grab the images /////////// Gallery gallery = (Gallery)findViewById(R.id.gallery); gallery.setAdapter(new Imageadapter(this)); gallery.setOnItemClickListener(new Adapterview.Onitemclicklistener() { @Override public void onItemClick(Adapterview<? > Parent, View view, int position, long id) {
//se chegar na ultima imagem, volta para a primeira
if (position >=9){
gallery.setAdapter(new ImageAdapter(getApplicationContext()));
return;
}
}
});
gallery.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return true;
}
});
///////fim da galeria de fotos
//I set a class to configure the images and such //start of image Adapter, picked up somewhere and improved for my use ///if you remember would give the credits
public class Imageadapter extends Basedapter{ private context; private int itemBackground; public Imageadapter(Context c){ context =c; Typedarray a = obtainStyledAttributes(R.styleable.Gallery1); itemBackground=a. getResourceId(R.styleable.Gallery1_android_galleryitembackground, 0); a. Recycle(); } @Override public int getCount(){ Return imagensID.length; } @Override public Object getItem(int position){ Return position; } @Override public long getItemId(int position){ Return position; } @Override public View getView(int position, View convertView, Viewgroup Parent){ Imageview imageView = new Imageview(context); imageView.setImageResource(imagensID[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setPadding(10, 10, 10, 10);
imageView.setLayoutParams(new Gallery.LayoutParams(650, 600));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
//take the image and arrow in the imageView with the setLayoutParams tamnaho public View getView1(int position, View convertView, Viewgroup Parent){ Imageview imageView = new Imageview(context); imageView.setImageResource(imagensID[position]); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setLayoutParams(new Gallery.Layoutparams(780, 1280)); imageView.setBackgroundResource(itemBackground); Return imageView; }
} ///end of image Adapter
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
Have you tried to store only their reference?
– user28595
What is your purpose?
– ramaral
@ramaral is the following to be able to pass by parameter, example
image[0], image[1]....
changing the numbers with an incrementer– Vale
@ramaral or using String to access them
– Vale
@Diegof not as it would be?
– Vale