First of all excuse me for my very bad English...
I'm a very very new developer and I'm confusing so much with search operation.
Actually I want to make a food and cooking app (with a lot of recipes and so on), and I want to add a search action to it, so the user could put multiple things (such as Ingredients) and the app show him the foods that have these things in their Ingredients.
Now I have two question.
First, how can I add tags to my "recipe activities" so when the ingredient typed app knows which recipes should showes? (My recipes are not in textview, they are all in imageviews).
Second, how can I completely separate the search keywords with ","? for finding the right recipes. (example: type "tomato", "chicken", "egg" and the app shows him/her the recipes that have these things in their Ingredients.)
I know you that now you are laughing so much for my gramer :), so after you laughted enough please answer my questions. Thank You SOOOOOOOOO MUUUUUUUUUCH.
You can use something like a map for every Recipe's ingredients a-la:
class Recipe
-name:String
-ingredients:Map < String, Quantity > or Set < String >
where Quantity represents all that nasty features used in culinary like spoons, cups, pinches.
Then you can search through keys of every recipe's ingredients. Name would be a tag you've mentioned.
You can read search string, parse it (e.g. into array with regular expression) and put into Set to avoid duplicates.
Related
I am trying to build an android app that the user can enter a string, and a list emoji related to that string would show up. (Just like Venmo app) For example:
case 1: User enters "pizz", and in the list there would be "π", note that the users enter "pizz", not pizza!
case 2: User enters "rabb", and in the list there would be "π" and "π°", note that the users enter "rabb", not rabbit!
What would be a good data structure and algorithm for this problem?
A trie is what your looking for. From Wikipedia
A trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is a kind of search treeβan ordered tree data structure ...
A trie is similar to a HashMap<K,V>, you can perform a lookup with keys and get a value. The difference is that you can also search by prefix. Given a prefix, it will find all the key-value pairs in the structure that have that prefix. It's basically the data structure for generating search suggestions.
General Idea:
Trie<String, String> t = new Trie<String, String>();
t.insert("pizza", "π");
t.insert("rabbit1", "π");
t.insert("rabbit2", "π°");
// then later...
t.findByPrefix("rabb"); // [π,π°]
Unfortunately, tries are too generic and are not present in any popular data structure libraries (like Java Collections Framework or Google Guava, for example). You'd have to implement one yourself or find an existing implementation and modify it.
I'd recommend:
Learning the theory. Watch this video. There are many more on YouTube that will teach you the basics. You can also search google for "N-way trie" and read notes about it.
Taking this class TrieST and modifying it. It's very similar (or already perfect) for what you need: http://algs4.cs.princeton.edu/52trie/TrieST.java.html see specifically thekeysWithPrefix method.
i was wondering if there is a chance to create comparable properties for objects defined by the user itself.
Following case: In my android app, the user creates a object "car", this object has predefined properties like color, size, doors, engine and so on ... but now, the user wants to add an individual property like "length" ... for that the user gets a plus button under the view to add this property ... now he can type in the wanted property, but what he dont want is to define the type of the input!
The users thinks "hey, its pretty obvious that length is expressed with a number so why i have to choose the type for this?"
I dont want to limit the user if i give them only predefined propertys.
I thought about saving every new parameter as a string, but then the values arent comparable anymore ... "900" is bigger than "1000" in a string comparison and so on. And i want to filter data and do queries later.
I dont disagree at all with the idea to let the user choose which type the field is, but i dont want to ask them too much in an android application.
If this all is not possible, how can i smartly get the information for the type from the user?
How can i handle this problem? Can someone give me a hint or keyword to search for?
Natural sorting might be the thing you are looking for. It will solve the problem with numbers.
II would like to create a scrollable list of items that can be sorted according to different criteria that can be chosen by the user from the action bar; I was thinking of a button that says:"Sort by...". I am working on an Android app.
I am developing a tourist guide, or rather, making an app out of a paper tourist guide I have previously written, thus I have a list of monuments through which the user can browse.
It would be great if the user could sort the items of the list in alphabetical order, or according to the rating of the monuments or on the basis of a tag indicating their type (historical building, museum, etc.).
Would it be even possible to display under the name of each item, like a sort of subtitle, a series of dots or stars indicating the above-mentioned rating?
At last but not the least, would it be possible, only when the monuments are sorted by name or rating, to automatically group them by another tag?
Like in some song player apps, when you choose an artist, you get all of his/her songs displayed often grouped by album. In my case the grouping tag would represent the zone in the city of the monuments.
Despite my experience in publishing, I am a newbie in Android (followed just a few courses) and the API docs made me very agoraphobic about coding. I know I am asking much so I don't demand a detailed explanation but a few suggestions about what could be a solution, a bunch of helpful guidelines and some names of specific API docs about Array Lists and sorting methods I should look at.
Thanks already for your help.
Firstly, you need to have a custom Java Object for a particular item
for example:
public class CustomItem{
private String Name;
private int Rating;
private String Tag;
// getters and setters
}
Then you can create a Listview with Input consisting of a List of type CustomItem. Here is a good ListView tutorial: http://www.vogella.com/tutorials/AndroidListView/article.html
You can then have somethibng like a Spinner, in which you can add the sort criteria. When the user selects one sort criteria, you can sort the Input List for the ListView and refresh the listview by doing: listView.getAdapter().notifyDataSetChanged();
Hope this helps.
I have an android app which displays quotes and have navigation to go to next quote and so on. would like to add "Save Quote As favourite" based on users selection of particular quote.
Once user saves Fav quotes and wants to see those quotes only, app should show those quotes.
Currently app reads the quotes from XML file. Let me know if any more information is required to understand the problem.
I would provide every quote with an ID (int). Whenever the user selects a quote to be a favourite, that ID is saved to a Set of integers. Later on if user decides to show favourites, you fetch all quotes with your IDs from the Set and show them in a appropriate view, for example a ListView
If you have a Quote class or something like that, you might as well put them in a collection whenever user decide his favourites, and show them in a ListView with a custom adapter.
I am new to both Android and Stack Overflow. I have started developing and Android App and I am wondering two things:
1) Is it possible to parametrize a TextView? Lets say I want to render a text message which states something like: "The user age is 38". Lets suppose that the user age is the result of an algorithm. Using some typical i18n framework I would write in my i18n file something like "The user age is {0}". Then at run time I would populate parameters accordingly. I haven't been able to figure out how to do this or similar approach in Android.
2) Let's suppose I have a complex object with many fields. Eg: PersonModel which has id, name, age, country, favorite video game, whatever. If I want to render all this information into a single layout in one of my activities the only way I have found is getting all needed TextViews by id and then populate them one by one through code.
I was wondering if there is some mapping / binding mechanism in which I can execute something like: render(myPerson, myView) and that automatically through reflection each of the model properties get mapped into each of the TextViews.
If someone has ever worked with SpringMVC, Im looking for something similar to their mechanism to map domain objects / models to views (e.g. spring:forms).
Thanks a lot in advanced for your help. Hope this is useful for somebody else =)
bye!
In answer to #1: You want String.format(). It'll let you do something like:
int age = 38;
String ageMessage = "The user age is %d";
myTextView.setText(String.format(ageMessage, age));
The two you'll use the most are %d for numbers and %s for strings. It uses printf format if you know it, if you don't there's a quicky tutorial in the Formatter docs.
For #2 I think you're doing it the best way there is (grab view hooks and fill them in manually). If you come across anything else I'd love to see it.