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)
Related
I am receiving a SoapObject with 2 properties having the same name. I want to remove one of them from the Object, and I am not sure how do I achieve that.
The purpose is, I actually want to read both the properties like:
soapObject.getProperty("PropertyName");
I have successfully tried using a for loop:
for(int i = 0; i < soapObject.getPropertyCount(); i++)
soapObject.getProperty(atIndex);
But, it doesn't serve my purpose. I need to retrieve them by name. So, how can I retrieve both?
I tried calling the method twice, but it returns the same values twice.
Have you already tried with the for each loop? It allows you to access both the key and, consequently, the value.
Here you can find an example from which you can start:
for (K key : map.keySet()) {
System.out.println(key + "=" + map.get(key));
}
If i have understood the problem statement correctly
you can remove the duplicate soap object by one of the following methods,(but first add it into an arraylist)
Using Iterator
Using LinkedHashSet. A better way (both time
complexity and ease of implementation wise) is to remove duplicates from an ArrayList is to convert it into a Set that does not allow duplicates
Using Java 8 Stream.distinct() You can use the distinct() method from the Stream API
I have arraylist like {23,45,44,78}. I have tried to get value at particular position and get difference of two but is there any best way to get diference of 23-45, 45-44 and so on
The pre-Java 8 way of doing this would be to just use a for loop:
for (int i=0; i < list.size()-1; ++i) {
System.out.println(list.get(i) - list.get(i+1));
}
Demo
There might be a slightly more compact way of doing this using streams.
I have a recyclerView in my app. I have 2 fields in it(image_view, price_text_view). The value of price_textview looks like Rs.8000. Now I wanted to keep scrolling until I find an item on the recyclerview whose price is more that Rs.4000(>4000). Can someone please help me with the matcher etc.?
I can't give you whole code here but can give you some logic for implementing this.
this can be done by For loop. And using ArrayList or Array you are passing in your Adapter.
Now lets assume you are passing Arralist to your Adapter say "arrayLst". and from your qustion I assume you are using ArrayList with HashMap.
so your ArraList would be like.
ArrayList<HashMap<String,String>> arrayList = new ArrayList<HashMap<String,String>>();
now do something like this.
for(int i = 0; i<arrayList.size; i++){
if(Integer.valueOf(arraylist.get(i).get("prise_tag")) > 4000){
yourlayoutManager.smoothScrollTo(i);
break;
}
}
I hope this will help you somehow.
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()
thank u for your time.
I was wondering if it is possible to get the id and name from a sql and place them both in the spinner.
with out creating a new AsyncTask and doInBackGround ect..
Witch will be active then onItemselected.
I have to little experience to make this decission.
With the JSON i have now working it only allows the ID or the NAME.
So i need to know if it is better to modify this JSON or create a new JSON with new php actions.
If i can get the confirmation to do this in the first this will save me time.
I am already 5 days at this problem.
Regards.
Nevermind i got it
private void loadSpinner(){
for (int i = 0; i < categoriesList.size(); i++) {
lables.add(categoriesList.get(i).getName() + categoriesList.get(i).getId());
}
}