i implemented two arraylists one with thumbnails (from Images.Thumbnails) and the other one with BUCKET_DISPLAY_NAMEs of each picture (from Images.Media).
Now i want to loop through it
for (int i = 0; i < thumbnails.size(); i++) {
if (bucket_display_names.get(i).equals("WhatsApp Images")) {
......
}
}
but i get an indexoutofbounds exception in the second line, meaning that the thumbnails array is greater than the one with the bucket_display_names... aren't they supposed to contain the same amount of pictures (in fact all of the phone)?
Check the way you are getting the list of the photo gallery. Maybe the following link can help you as a starting point: Get list of photo galleries on Android
Related
I am having a hard time with a piece of code that to my confidence it should work without a doubt but that is not the case.
public static void clearUnits() {
try{
for (int i = 1; i <= 3; i++) {
Log.d("S.G.E", inventoryPriceUnitsList.get(i).toString());
inventoryPriceUnitsList.remove(i);
recipePriceUnitList.remove(i);
}
}catch (Exception e){
e.printStackTrace();
}
}
The purpose of this code is to run through an array list of 4 elements and remove all elements after the first element. I know this is very basic and am sorry for wasting your time but I just needed someone else to look at this because I just don't understand why it's behaving like this. the result of this code is supposed to leave an array with one element (element 0) but instead, it leaves that and also the 3rd element. I also log all elements that are supposed to be removed and it shows up properly.
The problem is that when you remove an element from the array, the array shifts. So let's say in first round you remove the first element, then element 1 becomes element 0, and 2 becomes 1. Now on the next round you are removing the new element 1, which was the original 2, but the original 1 remains at position 0.
The simple solution is to iterate backwards, that way you are always removing elements past the point that you are at. For example
for (int i = 3; i >= 0; i--)
will work fine.
I have a list of objectId ,I want to use these objectId to use these in recycler view. Below is the given code I am using to get my desired results
for (int i = 0; i < wishList.size(); i++) {
q2.whereEqualTo("objectId", wishList.get(i));
}
But the problem is only last index values of wishList is applying to my queries, my guess is previous index values are being overriden .
If any other solution please suggest (without using parse relation)
I think you can just do
q2.whereContainedIn("objectId", wishList)
so I'm currently writing an app for android, and im still a noob in java/android.
Anyways i have this 2 strings, one with names and the other with emails, and i want to output them in a listview with a custom adapter.
It works fine so far but i dont know how to set the items dynamically (with a for loop).
To create the adapter and so on, I used this tutorial:
http://www.ezzylearning.com/tutorial/customizing-android-listview-items-with-custom-arrayadapter
I simply changed the ImageView to a second TextView.
In the tutorials code there are 5 items added to the list, but i need them dynamically, since Im not always having the same amount of name+emails to output
I already tried putting it in a for-loop by doing:
Weather weather_data[] = new Weather[names.length];
for(int z=0; z == names.length){
Weather[z]={new Weather(names[z], emails[z])};
}
I also tried it with adding "new" infront and trying to set everything null before, basically trial&error since i dont know much about it.
So can anyone tell me how I add the items dynamically?
(Ps: sorry if I used wrong names to describe anything)
This should work
Weather weather_data[] = new Weather[names.length];
for(int z=0; z < names.length; z++){
weather_data[z] = new Weather(names[z], emails[z]);
}
Give this a read to learn how for loops work
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
and this one for arrays
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
try this
ArrayList<Weather> weatherData = new ArrayList<>();
for (int i=0; i < names.length(); i++){
weatherData.add(new Weather(names[i], emails[i]));
}
Then when you need it as a Weather[] use weatherData.toArray()
I have to store image id for the image captured from camera.
Through this image id I can access its thumbnails and actual image considering those image resides on device already.
I have implemented this with image picker intent, but don't know if this is possible with Camera intent. The data when printed gives null, which for me doesn't seems to be notified to Mediastore.
Any idea or solution is appreciated.
Anyways, for a while I am implementing a workaround until I find the conventional way of doing it.
Currently my self solution is, to get a list of all the image IDs of both stages, before taking photo and after taking the photo. The new ID in new list is the ID I am looking for, when filtered with old list.
below is my code snippet.
private String getDiscrepantId(ArrayList<String> old_lst, ArrayList<String> new_lst){
for(int i=0; i<old_lst.size(); i++){
if(new_lst.contains(old_lst.get(i))){
new_lst.remove(old_lst.get(i));
}
}
return new_lst.get(0);
}
I hope there must be some better way to achieve this, which I believe someone will share it soon.
I am developing an Android game application.I have implemented the all the basic functionality.Designed all the screens.Now the main problem i am struck is I have to select 25 images randomly from 40 images.And display all the 25 images in the application.Can anyone guide me,,,, Thanks in advance
Regards
Tushar Sahni
I am assuming that you have all drawables in your drawable folder for imageview.
See the below implementation I have done in my app. First take Imageview array and int array with length of number of images you have.
ImageView i[]=new ImageView[49];
int id[]={R.drawable.pic1,......,R.drawable.pic40};
Then take arraylist like below and add no 1 to 40 to it.
ArrayList<Integer> ranArr = new ArrayList<Integer>();
for(int i=0;i<(40);i++)
{
ranArr.add(i);
}
Then shuffle it so your randomness will generate.
Collections.shuffle(ranArr);
Now your random no logic is over so you can now use that to imageview like below
for(int i=0;i<25;i++)
{
i[i]=(ImageView)findViewById(id[ranArr.get[i]);
}
So it will generate random images from your 40 drawables.
use Random class to generate 25 numbers, which are less than 40. Then get the images with generated numbers.