we are doing android chat application and want to save the values in the edit text(name of the user) to our database.When he updates it,the update should reflect in the database also.Any help in this regard will be really appreciable.
Thanks in advance.
Your question isn't very clear, but hopefully this will help:
Getting text from an EditText:
Get a handle on your EditText, then call the EditTexts .getText() method when the user presses the send button, or however your app works. So at the start of your activity:
EditText message;
protected void onCreate(Bundle savedInstanceState) {
//set layout
setContentView(R.layout.your_layout);
//Get EditText from id
message = (EditText) findViewById(R.id.edit_text_id);
}
Then in your send button's onclick method:
String my_message = message.getText().toString()
Store data in a database:
Read http://developer.android.com/guide/topics/data/data-storage.html#db The notepad tutorial it mentions is very easy to follow and will show you how to set up a simple database. That example covers adding new records to the database and modifying existing ones, which should be sufficient for you.
If you clarify what exactly you were having difficulty with, I'll be able to make my answer more specific.
Related
I have two edittext and save button. When application is started, last data will coming. I know SQL ite database for it but can I use a text file or another thing. Is Sqlite correct always? And can I give example for save data from two edittext , and I get data to edittext.
Developers Guide says:
"If you have a relatively small collection of key-values that you'd like to save, you should use the SharedPreferences APIs"
Hello people can someone help.
I have designed a dialog in which I would like to have a field box or some sort that when the dialog is called the TYPE & AMOUNT (link) box's will display the data from database on each item. So for this dialog I have made. The user will click drinks button on the activity before the dialog. And the data will fill theses field boxes once called.
My question is what can I use for this data box caller.
You can use TextView or EditText widget (depending on if you want user to just see or edit the data respectively) and you can pull data from SQLite Database.
In my Application I want to Add and Remove View (like Button, or Textview, Checkbox ) by Coding (Programming ).
In Details:
I have One EditText and One Add Button. User Enter Anything in EditText and Press the Add Button then this one is added in bellow LinearLayout, and whether User click on his/her added Button it will going to next LinearLayout.
I get sucess upto this.
but when user click the button in second LinearLayout then it will come back on first Linearlayout. I am getting error Here, i don't know where I made a Mistake.
And I also facing Problem about how can I Store this all. Like User Add 5 Button and closed the application and whenever he/she came back to application I need whatever he/she previously added.
Here is what i done.
http://dynamicandroidview.blogspot.com/2011/12/how-to-add-view-in-android-by-coding.html
Try to create a database table with minimum 2 columns in your case it will be id and buttonText.
Now when user clicks on the add button it will save text to the database and will create the button dynamically below any buttons which are already created before or as a new button.
Now in your onCreate method get the count of text thats stored in database.Some thing like the following code:
DB getData = DB.getInstance();
getData.open(this);
ArrayList<TextHolder> getList = new ArrayList<TextHolder>();
getList = getData.getAllTextFromGeT();
getData.close();
x = genList.size();
Here x will be the number/count of elements that are already stored in the database.Now you can another int say i and using this i and x in the for loop you can create buttons dynamically.
Inside the loop you can do something like the following to get text for all the buttons that are being created:
TextHolder firstOne = getList.get(i);
String text = firstOne.getText();
You will also need class with getters and setters method in order to convert DB elements into objects.Like in the above code getText() is our getter method which is getting elements from database and returning it here.
here text will be the text of the button.
So every-time users starts the application he will see all the buttons that he created when he ran the application before and newly added button will appear on the spot and also will be stored in the database for future retrieval.
Remember we are just storing text of the button and assigning it unique id which helps us to create the buttons.Hope this helps
I have this code for a username field for an Android app. I would like to validate the field to see if it is empty. Here is my code:
View a = findViewById(R.id.authentication);
(a.toString().equals(""))
I am guessing that you cannot use view to get the data entered by the user. What would be the best way to see if these fields are empty?
a.toString() does not do what you think it does.
Use TextView a = (TextView)findViewById(R.id.authentication); (a.getText().equals(""))
I was wandering if there is anyway to save a String from an EditText and clear it within the same onClick button.
The reason is I am creating a jumble word game where 1 player can jumble a word and then clear the word so the 2nd player cannot see it. The reason why I want to save the String is so I can match it with what player 2 enters.
Any advise would be helpful. Thanks
Place the following fragments of code in your onClick:
// Save
String text = someEditText.getText();
// Clear:
someEditText.setText("");