Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
Hi I wanted to show one activity only 3 times in android. Actually its a dialog which ask user some suggestion if user rejects it more than 3 times that dialog will not appear again unless and until user uninstall and reinstall the app.
Can anybody suggest me some solution to this.
Any help is appreciated.
This is for conditional display of dialog. I had performed a similar functionality earlier. You can do so by having a counting variable in the sqlite. Each time the user rejects the dialog for suggestion, fetch the entry from the database, check if it is less than or equal to 3. If less than 3, then display the dialog, update the database entry by incrementing count variable by 1. Otherwise, if more than 3, do not display the dialog.
Creating a database and initializing the variable:
SQLiteDatabase db=openOrCreateDatabase("MYDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS myTbl(Name VARCHAR,num VARCHAR);");
//Here, Name is the name of your counting variable and num is the value you want to store in it
String name="count";
String num="0";
String s="INSERT INTO myTbl VALUES ('"+name+"','"+num+"');";
db.execSQL(s);
Log.d("myapp", "Insertion of data successfull");
db.close();
The advantage of using this approach is that, once the application is uninstalled, its corresponding sqlite database will also be deleted. Hence, this will ensure that if the user ignore the dialog for more than 3 times, then the dialog will not launch as long as the application is uninstalled and reinstalled. Regarding updating the values in sqlite, i hope you know the basics.
Hope this has helped
Create a SharedPreferances save 0 as initial value in it, on user rejection, increment the value by 1 and save it in SharedPreferances, once the value reaches to 3, don’t start the activity again. You can use database instead of sharedPreferances.
You should use SharedPreferances for counting the value of showing suggestion like 0 to 3. For the suggestion show you can use separate layout and use include it to your main layout. Then the complexity of activity handling will be reduced. When the layout is showed three times then the specific layout should not be shown by setting it's visibility GONE.
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
I worked on how to input data into java derby database, but once I save my data into database and needs previewing my data always come up with null e.g nullFemale or nullMale. While I need only Female and Male to be displayed, how to solve this please........
enter image description here
My code is
my code
GENDER is null. Then you modify it using
GENDER += male.getText() + "";
So you concatenate null with the actual gender.
Just don't do that. Just use
GENDER = male.getText()
There is no reason to use concatenation. And GENDER shouldn't even be an instance variable. it should be a local variable.
Notes:
Post your code as text in the question. Blind people can't read your images. I can't copy-paste code from your images. People behind firewalls can't read your images. Next time, I'll simply vote to close your question, since it doesn't respect the rules.
Respect the Java naming conventions. ALL_CAPS is for constants (static final variables). Not for variables.
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
I am writing a report generation program in Java, with oracle DB. I have a stored procedure, that will retrieve one value at a time. From my Java Program I am calling the procedure repeatedly. In extreme case, I have to call the procedure 60,000 times. But it shows problems like, wrong value is returned after a specified calls (like 300 calls). kindly tell me how to sort out this.
Thanks.
Its not a good practice to call DB with such high frequency. You can use cursor in your stored procedure and fetch the required records at once. Check the link for reference Cursors in Oracle Stored Procedure
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to add 5 markers (city locations) on a map and every time a users is passing nearby, I want to display the user a message: You have just passed the first location, then second location and so on.
How can I achieve this? I this even possible with Firebase?
Well, since the question is rather unspecific about the details, here's a rather broad answer of how I would personally approach solving the problem:
So from what I understand the problem is split up into the following parts:
Displaying markers on a map
Listening to user location
Comparing user location to marker locations
Displaying messages
Displaying markers on a map
I'm assuming that you were thinking about using the Google maps API to do so, therefore I would recommend looking at the following: Adding a map with a marker
Listening to user location
Listening to user location is explained in the following document: Location Strategies. Multiple approaches are listed on how to get the users location, matching your specific needs.
Comparing user location to marker locations
I personally would recommend using your Noodle over here. I can't do all the thinking for you, but somehow you must have the location coordinates of the markers stored and accessible for comparison with the user's location updates. I would also keep track of whether a 'checkpoint' has been visited or not already in order to avoid displaying messages excessively.
Displaying messages
Last but not least, displaying of the messages. I would use Toasts to display to the user that they have passed a checkpoint. A smart way to do this would be to have this happen in the onLocationChanged method that you're going to have to override for listening to location updates, and simply display a toast when you're comparing locations method tells you so.
I personally do not see the need to add firebase to this, since no storing or getting of data from a DB is necessary. Everything can be done locally.
P.S. don't forget to mark this as the right answer if it ended up helping you!
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 5 years ago.
Improve this question
I have a some trouble about my own simple android project. I save data pair (key-value), and I dont want to save same data. ( for example: I save the data "Car"- "Blue" once. and then application can not permisson save again same the data.) I wrote already update method but I couldnt use for search & control data repetition. How can I solve ?
Make the combination of the two columns a Primary Key
You can also use if else block along with SELECT statement to validate inputs.
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 6 years ago.
Improve this question
I am using four ProgressBars in my AndroidApp.
First of all I want them all to be empty, and when I update a Variable, I want one of the ProgressBars to get filled a bit. But only up to a "goal" that I want to set in beforehand. For example as soon as the Variable hits 1000, the ProgressBar should be filled and a message should pop up or something like that, when the variable is 500, it should be halfway filled and so on.
These are my problems, I think they might all be solved by knowing how to bind a ProgressBar to a variable? If so, please tell me how I can achieve that, else, please tell me how I can still get my plan done. THANK YOU!
You can set the progress bar max value to 1000 and then rather than set the variable to 500, set the progress value to 500.
Here an example of binding the progress bar is:
Can i databind a ProgressBar in Android?