Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a list of courses and I need to filter them while searching
I need to be able to search for every word the user enters
For example: if I have course called nutrition basics, If I enter in search bar basics nothing show up but if i enters nut or even n it works.
Here is my code:
itemFilter: (suggestion, input) => suggestion.name .toLowerCase() .startsWith(input.toLowerCase()),
How can I do the filter as I want? I need to search even if for letter 'b' and still get the result nutrition basics.
I'm using flutter and firebase.
Note: I tried contains insteadof startWith, but if i have two courses one nutrition basics and other math 500 basics and i searched for word basics the result shows after enter is only nutrition, also i need to be able to search for letters too, as b in basics or c..
Thanks.
You have used method startsWith
itemFilter: (suggestion, input) => suggestion.name .toLowerCase() .startsWith(input.toLowerCase()),
use contains instead of startsWith
itemFilter: (suggestion, input) => suggestion.name .toLowerCase() .contains(input.toLowerCase()),
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
suppose there exist a form and has two button ,i want one button to get disabled until all parameter is filled by user while other Enabled,for users to navigate to back panel.Is there exist a function to assign unique id to buttons?
Edit1: Tried to disable one of the button,until all the text-form field in the page is touched by users,once user enters all the required parameters ,then the button gets enabled!
You don't need a unique id for that
FlatButton(Text('foo'), onPressed: areAllParametersFilled ? _onFooPressed : null),
FlatButton(Text('bar'), onPressed: !areAllParametersFilled ? _onBarPressed : null),
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Both of the codes below give me the same exact answers. I was just wondering which would be better programming practice for readability and maintainability. Would less lines of code be best? Would one affect the functionality of the program more than the other? any suggestions would be very much appreciated as I just want to learn the best practices for programming.
Here are the codes:
for (int i = 0; i < db.getAllDecks().size(); i++)
{
String CardCount = String.format("(%s)",db.getCardsForDeck(i+1).size());
adapter2.add(db.getAllDecks().get(i).getDeck_name());
adapter3.add(CardCount);
}
or
for (Deck deck: deckList) {
String deckName = deck.getDeck_name();
adapter2.add(deckName);
int count = db.getCardIds(deck).length;
String strCount = Integer.toString(count);
adapter3.add(strCount);
}
Overall, I think the second code is clearer, and more readable.
It contains moe variable names that is able to tell what exactly it is used for, such as deckName, count and strCount. I can clearly see that you are getting every deck's name and card count and put them in different (list?) adapters.
For the first one, I apparently needed more time to comprehend what it is doing. So IMO, the second one!
Also if you could just rename getDeck_name to getDeckName that would be better for people to read. getDeckName follows the naming convention for naming Java methods i.e. camelCase.
if you want to get data from simple list thnn foreach loop is good to use but,,, if you want to data from exact position or to store from id than for-loop is better ..
and there is NO difference by performance wise both are same as well, as i know.
as my suggestion use for loop :)
As per this book Code Complete - Steve McConnell's
for loop is good choice when you need a loop that executes a specified number of times.
foreach loop is useful for performing an operation on each member of an array or the container.
for more visit : Google books - Code Complete
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am a beginner at programming Android, please help with this simple project.
I want an integer to show up in toast, which I write in textBox. I do not know what to put in the highlighted part here.
Sorry for the link, but I cannot post the picture
You need to use the getText() method to get the text the user entered.
Change the myEdit declaration to:
final EditText myEdit = ... ;
and then use:
Toast.makeText(MainActivity.this, myEdit.getText().toString(), ...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am a beginner in Android, and understand only very basically that HashMap class enables key/value pairs. But how does this translate into actually using this in an Android app? Could someone provide a simple, plain English example of what case you might want to use HashMap in an app? I cannot imagine a case where I might need it. Make up an Android app idea, if needed. Thanks in advance.
I am looking for a "big picture" analysis that will give some examples where you might use HashMap with certain Android functionalities you are trying to implement.
HashMap or Map interface is not new on android, This is Java Collections framework.
Java collection are meant to be used in several cases to hold data and contain 3 interfaces:
List - Basically simple list,or linked list implementations
Set - The same as list but won't hold 2 equal obejcts(You need to implement you own equals and hashcode)
Map - as you said key value pair.
Uses:
List - For anything, just to hold data
Set - For list of data that we want that all of the items will be unique.
Map - Key value and the most common example is the use for DB items, or something with ids.. for example:
bookId, Book.. I that case you can take the object by id.. This is the most common
I attached link for Java collection tutorial.. It is very important framework that you have to know if you are going to develop java/android
http://tutorials.jenkov.com/java-collections/index.html
Hope that helps
We could use HashMap to keep a list of employess together with their respective salaries.
We can do:
HashMap<String, Float> emplMap = new HashMap<String, Float>();
emplMap.put("fred", 1.000);
for(String name : emplMap.keySet()) {
System.out.print(name + "'s salary is" + emplMap.get(name));
}
Should print
"fred's salary 1.000"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a large file of about 10 MB, I want to search a specific string, and this specific string may be used a lot of times in 10 Mb text file. I need results where this specific string is used. I want to do search like Google. For example when i write a string then google comes with matching Patterns . Your suggestions will be appreciated.
file formate
he is going to school.
we should do best deeds.
we should work hard.
.
.
.
.
Always speak truth.
i have search edit field in my application.
user write "should" in search edit field.and press search button.
a list should be opened in which searched words come with it's complete line.
for example result should be
we should do best deeds.
we should work hard.
A simple way to search a file and get a match "with context" is to use grep. For example, to match every line with "hello", and print one line before and three lines after, you would do
grep -b1 -a3 'hello' myBigFile.txt
You can use grep -E to allow for a wide range of PCRE regex syntax.
Without more detail it would be hard to give you a better answer.
EDIT 2
Now that you have explained your problem more clearly, here is a possible approach:
InputStream fileIn;
BufferedReader bufRd;
String line, pattern;
pattern = "should"; // get the pattern from the user, do not hard code. Example only
fileIn = new FileInputStream("myBigTextfile.txt");
bufRd = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8")));
while ((line = bufRd.readLine()) != null) {
if(line.contains(pattern)) {
System.out.println(line); // echo matching line to output
}
}
// Done with the file
br.close();
If you need to match with wildcards, then you might replace the line.contains with something that is a little more "hard core regex" - for example
matchPattern = Pattern.compile("/should.+not/");
(only need to do that once - after getting input, and before opening file) and change the condition to
if (matchPattern.matcher(line).find())
Note - code adapted from / inspired by https://stackoverflow.com/a/7413900/1967396 but not tested.
Note there are no for loops... maybe the boss will be happy now.
By the way - if you edit your original question with all the information you provided in the comments (both to this answer and to the original question) I think the question can be re-opened.
If you expect the user to do many searches it may be faster to read the entire file into memory once. But that's outside of the scope of your question, I think.