Emptying Parse.com Array field in android - android

I have created a Parse.com class in which a field type is Array. I save List with the following code:
public void setPreperties(List<String> properties){
put("properties", properties);
}
The are two senarios:
Users will either select one or more properties
Or they will select no properties at all.
If the user has selected properties, its saved with the above code.
When the user deselectes all the properties and click save, I pass null to the above method to save. But this gives NullPointerException.
My question is how can I save empty data in the Array?

Try passing an empty list, like Collections.emptyList() or new ArrayList<String>().

Related

How to get edited AutoCompleteTextField value into form data

Using Flutter I have a form that contains an AutoCompleteTextField, I am trying to get changing of the value of the text field working. The value to be edited is placed into the AutoCompleteTextField when the form is opened using the technique linked to my previous question:
How to set the initial value of Flutter autocomplete_textfield
Now I find that if I try to change the value of the field the autocompletion appears to work, but the new text does not appear in the form data when the form is submitted, the previous entry remains. I have tried adding the new text to the form data but this does not change the behavior.
The "itemSubmitted" code looks like:
itemSubmitted: (species) {
setState(() {
searchTextField.textField.controller.text = species.commonName;
});
The submit method calls validate and save on the form data:
if (_formKey.currentState.validate() == false) {
return;
}
_formKey.currentState.save();
What more do I need to do to get the new selection in the AutoCOmpleteTextField updated in the firm data?
Update:
It appears that if I start with a blank form I am able to search for an entry in the AutoCompleteTextField, save the data to my database (without clearing the form), search for a new value, and the data is correctly placed into the form data each time. This suggests that the initialization of the field when the form is opened is causing the issue.
Sid
This issue was entirely of my own making, I am using the same code to both create and edit an entry. To differentiate between new and edit I was testing for valid object being passed to the page, my mistake was that when my text search field was updated I was simply checking if there was a valid object had been passed to the page, of course, the new data was in the form data structure and was never being placed into the object being edited.
The solution was to simply first check if there is a valid input object, if there is then a secondary test is made to see if the form data matched the input object, if not the new data is then placed into the input object.

Firebase overwrites existing records instead of appending them

I am a bit new to Firebase and so have been playing around with to help myself get more acquainted with it. So while I was playing around with realtime databases, I was trying to append data to the JSON tree. The code is as below
mSaudi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
count++;
mHistory = mChildRef.child(Integer.toString(count));
current = riyadh;
mChildRef.setValue(riyadh);
mHistory.push().setValue("riyadh");
}
});
The tree which I require is something like this:
value:
1: some text
2: some other text
But what's a actually happening is this:
value:
1: some text
and on updation
value:
2:some text
the previous entry gets erased
I have tried changing the references in various ways but to no avail. Any help in this regard would be appreciated.
If you would like to save both values, you have to save them using a variable such as a Hashmap. If you save a string and then try save another one under the same branch, it will delete everything previously saved. So try the following
HashMap<String, String> map = new HashMap<>();
map.put("1","String");
map.put("2","String");
mHistory.push().setValue(map);
This will save both the strings without deleting one.
If you would only like to add one String
mHistory.push().child("1").setValue("Your first String");
The biggest problem with this though is that everytime you use push() you generate a random key, so you would have to save the key as a string and use it as a reference in your child.
When you set a value on Firebase, it is going to replace everything in, and under the reference.
Let's say that you have a house value, with 2 childs: Color and Size.
If you want to edit only the color value, before the setValue(), you will have to change the reference you are pushing to.
If your reference was getReference().child("houses") and you push something there, it's going to replace everything there and below it. The way to do it is create a new reference (or update the previews one) like this: getReference().child("houses").child(houseKey).child("color") and push your String there.
In your example, you will need to add the field you want to change as a child before the push() method.
The other way was already told by #Janwilx72 and is getting the whole object, updating the value locally and pushing the entire object again.
You can try this
mChildRef.child("2").setValue("some text");
It should be appending new item instead of overwriting them

Android - using Adapter with object

I have an object called "EntityType en" which contains a string "Name" i want to use Array Adapter to check the index of the given object but without defining my list in the R.layout because it is defined in by the object.
What I am trying to do is showing my data (array) in a menu dialog that lets the user select the desired "Name".

Android get data from the parse table (json file) (imported in parse.com-data browser)

I have one json file, that I imported in parse.com->data browser->import partition. I can get the String and image value from the table but I have no idea about how to get following values. First column have name chapters of type array look like one field following,
[{"__type":"Pointer","className":"Chapter","objectId":"BCr3uAnapV"}]
how to get above value and second column have, name user of type object look like following,
{"password":"xxx"}
Please any one help me for above, I have tried Googling but it did not help.
EDIT:
See following screen shot: arrow display column 1) chapter and have another column 2) user I want to fetch (get ) that for e.g. if we want to get data of String type like: String provider = (String) objectList.get(i).get("provider"); this manner this way I want to above data, below my screen shot:
This line is a relation (of type Pointer) to another Class in Parse:
[{"__type":"Pointer","className":"Chapter","objectId":"BCr3uAnapV"}]
The class being Chapter. You can make sure this object is fetched together with the object pointing to it using "include":
query.include("chapter");
When you query for the other object, using query.include on pointer relations will ensure these related objects are fetched as well.

How to do list box in android

am trying to do .when i click a button opens another activity and shows list box. In that list box display a list of values of particular column of table. that is we have to retrieve from
sqlite database.
how to do??
like this:
http://www.google.co.in/imgres?imgurl=http%3A%2F%2Fwww.tutorialspoint.com%2Fimages%2Ftk-combobox.jpg&imgrefurl=http%3A%2F%2Fwww.tutorialspoint.com%2Fruby%2Fruby_tk_combobox.htm&docid=SVhMpjb5FMImxM&tbnid=l4yuDUmNF-lm5M&w=220&h=242&ei=HBNRUay8B8OUrgeA94CYDw&ved=0CAcQxiAwBQ&iact=ricl
Fetch the results from database
Put it in a adapter
Populate android spinner with the adapter
Use the link below for reference
http://developer.android.com/guide/topics/ui/controls/spinner.html
Answer is to big so don't possible entire code i am just giving you guide line.
Step:
You have to fetch all record in database and store into Collection class variable.
Set those variable to adapter.
You have to used onClick and get information which is require.
You can refer this tutorial may be helpful.If this is helpful then accept answer.

Categories

Resources