I want to group all contact in my app by using the first character of contact name. The result looks like deafault Contact Book in Android Phone.
I don't know the name of API which can solve my problem.
Could you give me the name of it?
Picture figures: image
You can use the an object of TreeSet class to sort strings as shown below:
TreeSet mySet = new TreeSet();
mySet.add("java");
mySet.add("C");
mySet.add("Pascal");
mySet.add("ruby");
Log.d("TAG",mySet);//output here will be C,java,Pascal,ruby,
//Now our task is to fetch strings from the sorted strings in `mySet` object
String[] names= mySet.toArray(new String[mySet.size()]);
//Now you will have sorted names in the names[] array
So, as commented if you are able to fetch string/names from your contacts, then you can use the above concept by creating an object of type TreeSet and adding all your contacts to this object and converting it to an array of strings as shown above.
I'm sure this one definitely helps.
Related
I would like to know if there is a way to use an "AND" filter in a query on the parse server. In my case, I would like to filter posts by categories, for example, I have a colum "tags" (an array), and there, all the tags that are related to that post are. I retrieve the tags that the user is intersted with, and then I query to find posts that contain any of those tags ...
ParseQuery<ParseObject> query = ParseQuery.getQuery("Posts");
ArrayList<String> tags = (ArrayList<String>)object.get("myTags");
query.whereContainedIn("tags", tags);
The problem with this query is that it brings very vague answers, for example, a user follows a "Curiosities" tag, and also follows the tag "Avengers", I want to show it first, posts that contain these 2 tags, not only one of them.
whereContainedIn will find objects where a particular key's contains one of the elements in the passed array.
To get objects where a particular key contains all of the elements in a passed array, use whereContainedAll.
Note, though, if you're aim is to list matches in order, where objects matching all tags are listed first, followed by objects matching some tags. Then you'll need to query with the more permissive version (whereContainedIn) and do the sort -- sorting by matching tag count -- on the client.
According to Parse Server docs..
String[] names = {"Jonathan Walsh", "Dario Wunsch", "Shawn Simon"};
query.whereContainedIn("playerName", Arrays.asList(names));
https://docs.parseplatform.org/android/guide/#query-constraints
I have a raw json file like this
{"_id":707860,"name":"Hurzuf","country":"UA","coord":{"lon":34.283333,"lat":44.549999}}
{"_id":519188,"name":"Novinki","country":"RU","coord":{"lon":37.666668,"lat":55.683334}}
{"_id":1283378,"name":"Gorkhā","country":"NP","coord":{"lon":84.633331,"lat":28}}
{"_id":1270260,"name":"State of Haryāna","country":"IN","coord":{"lon":76,"lat":29}}
{"_id":708546,"name":"Holubynka","country":"UA","coord":{"lon":33.900002,"lat":44.599998}}
{"_id":1283710,"name":"Bāgmatī Zone","country":"NP","coord":{"lon":85.416664,"lat":28}}
{"_id":529334,"name":"Mar’ina Roshcha","country":"RU","coord":{"lon":37.611111,"lat":55.796391}}
{"_id":1269750,"name":"Republic of India","country":"IN","coord":{"lon":77,"lat":20}}
{"_id":1283240,"name":"Kathmandu","country":"NP","coord":{"lon":85.316666,"lat":27.716667}}
{"_id":703363,"name":"Laspi","country":"UA","coord":{"lon":33.733334,"lat":44.416668}}
It is NOT an JSON array - it is a huge list of JSON objects. Here Populate the spinner from JSON In Android, here Convert json array to list of json(raw) strings here android how to convert json array to string array or even here https://developer.android.com/guide/topics/ui/controls/spinner.html it is assumed that I have a JSON array or static data. I'd like to have two spinners in which one is for country and second one is for city. Let's assume I have list of countries so it will be a static data. I'd like the second spinner to dynamically load from raw json file all cities that corresponds to selected city in first spinner. I think that I can handle spinners thing but how can I load data from raw json file into spinner? Do I need to modify this raw file so that it will be a json array and then do something like this:
JSONArray jsonArray = new JSONArray(arraytitle);
List<String> list = new ArrayList<String());
for(int i = 0 ; i < jsonArray.length();i++){
list.add(jsonArray.getJSONObject(i));
}
EDIT
I found this answer https://stackoverflow.com/a/26780581/4671908 - if I will succeed I will post an answer
So you have two questions:
How to update the second Spinner dynamically when the first Spinner is updated
Three thing you need to do:
Implement AdapterView.OnItemSelectedListener
Update the backed data set inside the adapter of the second Spinner. In your case it would be a list of city. (To do this you need to create your own adapter extended from ArrayAdapter)
Call adapter.notifyDataSetChanged()
How to use the JSON
There are several solutions there. But it would be hard for others to provide the one that would suit your case the best without knowing any detail of the requirement.
Just remember one thing when you face design problem:
Do the simplest thing first.
I have a Place object, containing an array with objectIds for Tag objects.
An example of an array:
[[{"__type":"Pointer","className":"FavoriteTag","objectId":"Toc5sVlzVd"},{"__type":"Pointer","className":"FavoriteTag","objectId":"cUxcl0IFFv"}]]
My first workflow way too slow:
query each Place object, get the array and parse it to find each objectId
get the corresponding Place with the objectId
The workflow I'm trying:
Find the objectId of each matching Tag object
Put these objectIds in a ArrayList
Get each Place object that contains a matching objectId from the arraylist
I don't know how to do step 3.
I'm trying:
parseQueryFavoritePlaces.whereEqualTo("tags", arrayListTagsObjectIds);
and
parseQueryFavoritePlaces.whereContainedIn("tags", arrayListTagsObjectIds);
but no luck so far.
Am I on the right track here?
Try giving this a shot:
query.whereContainedIn(String key, Collection<? extends Object> values)
According to the Parse documentation this adds a constraint to the query that requires a particular key's value to be contained in the provided list of values.
Here's the ParseQuery documentation if you think that might be useful!
I want to store city names by country in an array.
This is my code
String cities[][]=new String[10][20];
I want to assign all cities of a country one time like this.
cities["USA"]={"NEW YORK","WASHINGTON"}
cities["UK"]={"LONDON","CAMBRIDGE","CARLISLE"}
then I want to use like this
String mycity=cities["UK"][2];
but eclipse shows error for assigning values. how can I use this arrays?
Try like this,
String cities[][]={
{"NEW YORK","WASHINGTON"},
{"LONDON","CAMBRIDGE","CARLISLE"}
};
And
cities[0][0]
will return NEW YORK
May be this helps you.
Better you can use a HashMap - List combination like this
HashMap<String,HashMap<String,List<String>>> cities = new HashMap<>();
Refer following links for more details Storing HashMap inside HashMap,
Storing a HashMap inside another HashMap and improving performance
I have a doubt. I have 3 array list dynamic values. I need to display these dynamic values in a listview. can someone please tell me how can i achieve this.
I have name[] array, status[] array and image[] array. I need to dynamically display the values in listview in a android sample
This is what i have:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,NameList);
In this i am able to display i am able to display all the names in NameList[].
An array list only accepts an array of values, so as you see, you can only pass in the names. You have two options,
The simple option is to create a compound object, say Person, that has a name, status, and image. Then you create a Person[], and create the array list on that, and pass it into the array adapter. You must implement Person.toString() to print out the Person object as you'd like.
If you need to be able to lay out the Person fields in a more flexible way then you could simply by implementing toString() on Person, you need to create a custom list adapter. You can take a look at this post to get you started,
Categorise the listview