I'm a beginner in android studio and was working on it for last few weeks and finally stuck with a problem. so how can we extract data entered in the text widgets to use them in our java code. For example I was working on making an application where the user will enter any random sequence of digits in a edit text widget and then can choose any sorting methods I've provided using buttons , after that the result will be shown in a text view widget. But in order to do this I need to have access to the data user have entered in the edit text widget. I already know that we can get their data using getText() and setText() but it's not working when I'm trying to
store the data in a normal primitive variable. I want to know how can I store that data in a normal java primitive variable to use them in my java code.
Any help would be appreciated.
Related
I am working on a project of question paper generator(offline) which requires the the user to input the questions. Obviously there will be some questions of mathematics as well hence I need to invoke or create a text editor that will create mathematical expressions such as integral symbol or limit operator etc.
I am using java swing GUI and mysql database to achieve the purpose and hoping to use JEditorPane for text area.
Please help me , I took about a day to search the internet to solve this problem.
And also I need to know whether the mathematical expression the text editor will create could be stored in mysql database column?
Things I tried:-
Tried changing the text type of JEditorPane to text/html but I realised that I can add subscript, superscript and even images but this wont add that beautiful LaTeX mathematical expressions and many complex operators.
Tried using JMathTex but I couldn't resolve how it will enable the user to input the expressions, according to me JMathTex is not the solution to my problem.
Even thought tries of using MathJax but it requires java script and JEditorPane does not support java script.
I repeat the problem, I want to create a text editor (just like MathType) in my swing application so that user can input the question along with the required expressions so that the question can be added to database for random generation.
Can anybody please let me know how to read the values of Excel form controls (radio button, checkbox, drop-down etc) in Java?
I tried using Apache POI, but I couldn't find a way to read the value of radio buttons or checkbox.
I know that I can link the form control with a particular cell in excel, and when the value of form control changes, read the data from that cell. But, instead of following this approach, I am looking for a way to directly read the value of form control.
I searched google but couldn't find anything useful. So can anybody please help me here?
I do not have any limitation of using any API's. So please let me know if this can be done in Java or not.
I've scoured for the answer for this. I have a simple text based game. I make a choice with a radio button, and confirm it with a button click. I've set the game to save for when I change to landscape from portrait view.
But I cannot for the life of me find how to save the game when the back button is pressed.
I'd like to have a simple menu on the title screen with three buttons, one of them being "Continue" which would restore the game's saved settings. And obviously, one in the action menu I already have set up which would reset all the game data.
I've tried sharedPreferences etc. if someone can tell me the way to save the game data by using SQL so no user can mess with the data, that'd be better.
Thank you in advance for you help.
on edit I realized my question is not specific enough. I am trying to retain the state of a TextView which I am modifying with user choices, thus changing the text. Every time the app is restarted, the first text loads.
It kind of depends on how much information you want to save, but if it's very little I'd look in to shared preferences which saves key value pares. If it contains a bit more, you should look in to SQLLite which is just a database for your app on the device.
Further reading:
SharedPreferences:
https://developer.android.com/training/basics/data-storage/shared-preferences.html
SQLLite:
https://developer.android.com/training/basics/data-storage/databases.html
Have you tried serialization? Put the informations in a file, like a text file, then simply un-serialize it and take back the informations. You can always encrypt it if you don't want anyone to change the datas, like a real game save file.
I am currently working on a Java applet. The Java app has a text box which only allows plain text (Java code) to be written which will then be converted to visually represent the codes written by the user, i.e assume the user has created a linked list, I have to display the linked list using Grahics2D to draw boxes and all. I'm not able to interpret the codes written by the user in the text area. I would be very grateful to receive some of your help.
I have tried to solve the issue using Beanshell like this:
Interpreter bsh = new Interpreter();
bsh.eval("import java.lang.String;");
bsh.eval(srcCode);
Where srcCode is the text I have retrived from the text field like this:
txtCode.getText()
The interpreter is not able to compile classes written by the user.
How could I solve the issue I'm having?
In my app, i have you put in some information through some edit text. Then you hit this button and it starts another activity that does some calculations and then displays results through text views. Well i want to be able to save all of those text views, and then open them up later. On the home screen i have a load button. When you click it, I want to be able to see the stuff I've saved and be able to open it by clicking on it. I'm new to android, so I'm having a hard time figuring this out. How should I go about doing this?
Use SharedPreferences...Check out..
http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html
http://androiddeveloperspot.blogspot.in/2013/01/sharedpreference-in-android.html
this will help.
I see two questions in your question. The first is how to pass data from one Android activity to another.
The best way to do that is by using the putExtra method of the Intent class and then the getExtras method to extract the data in the receiving activity. Please see this SO quest and answers for more details.
For your second question, how to save data that can be recalled at a later by the main activity, you can use the SharedPreferences APIs. See this web page for more information on that. Basically the shared preferences APIs allow you to save key-value pairs of information which in your case can be field names (keys) and their associated values. For this you would want private preferences and pick a unique name for this preference file.