How to use spinner to store values to Firebase? [closed] - android

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 am creating a Classified application, I am stuck at Post Activity, where the user needs to select the Category to post their products. Below is the rough sketch for Post Activity.
Firebase Database Structure :
How to let the user select the Category from the Category list and based on that Category the item/products needs to be saved under that Structure.
For example : If the user needs to post an Advertisement for Audi, he will select "Cars" from the spinner list and that info(image,price,name) should be saved under "Cars" structure in the Firebase Database. Any help would be appreciated, I need to know the logic behind this:

You can get spinner text like this.
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
After you got selected text you can set DatabaseReference location.
databaseReference = FirebaseDatabase.getInstance().getReference().child("All Categories").child(text);

Related

How do I see all my data that has been read in Cloud Firestore? [closed]

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 2 years ago.
Improve this question
I have successfully read all my user data into cloud firestore but unable to see all my data in one go.
As you can see in the screen capture, "Sara" has been read. Beforehand, "Mira" and "Kiena" has also been read.
How do I see "Mira" and "Kiena" together with "Sara" in one screen? I want to see all the data that has been read in Cloud Firestore.
I need to have all this as a record for my thesis.
I set the user data with this code:
private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("sampleData/userdata");
You need to add this
SetOptions.merge()
inside the set function in your code
what is happening now is that firestore takes a key = name and values = sara/mira/etc and keeps overriding the values since the key is the same, but when you use the merge options it will not override and will display all in a list
It looks like you're setting the user data with something like:
db.collection("sampleData").document("userData").set(...)
Any time you execute this code, you're overwriting whatever data already exists in userData.
If you want to create a new document each time you run the code, do:
db.collection("sampleData").add(...)
This will generate a new document with a unique ID each time you execute it.
If the document needs to be associated with the current user from Firebase Authentication, you'll want to use the user's UID as the document name. That'd look like this:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
db.collection("sampleData").document(uid).set(...)

How to insert multiple data in firebase using loop [closed]

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 4 years ago.
Improve this question
Is there any way to insert multiple data in firebase using loop in android studio.
As
for (DataSnapshot ds : dataSnapshot.getChildren())
{
String Name = ds.child("Name").getValue().toString();
list.add(Name);
}
DataSnapshot loop is used to get the multiple children. How can i insert multiple data using loop.
I am guessing you want to update various children of your database at once and for that you do not need to actually use a loop to insert multiple data at once in Firebase.
You may use maps for that, which can update multiple fields of your database in one go. The code for using maps, looks something like this:
Map<String,Object> taskMap = new HashMap<>();
taskMap.put("age", "12");
taskMap.put("gender", "male");
taskMap.put("name", "Someone");
taskMap.put("surname", "no-one");
reference.updateChildren(taskMap);
This depends a lot on your database structure, and you can edit it for your need, according to your database structure.
To know more about, how to update database using maps, go through the following links:
Link1
and
Link2.
Also, if you could make the question a bit more precise, you can get more help from here.

how do i user pattern matches like search engine [closed]

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 7 years ago.
Improve this question
I want to generate Search Suggestions that matches the input in the AutoCompleteTextView.
It will check for the matches for the first word I type then all the related words should be populated.
After I type next character then it will match combination of that word and populate the result .
I do not understand how to do pattern matches.
For example: Suppose, there are three country names.
INDIA, IRAQ, IRAN.
When I type I then I want get All Country names Starting with I to be displayed.
When I type IR then result should be IRAN,IRAQ. ETC.
Your requirement will be satisfied in AutoCompleteTextView itself.
Threshold is used to set from the length where auto complete show it's suggestion:
For ex:
String[] languages={"INDIA", "IRAQ","IRAN"};
AutoCompleteTextView text(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,languages);
text.setAdapter(adapter);
text.setThreshold(1);

Place data from jsonobject into AutoCompleteTextview [closed]

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 8 years ago.
Improve this question
I need to get data from http://schedule.sumdu.edu.ua/index/json?method=getTeachers, parse it and load into AutoCompleteTextview. Any suggestions?
You need to access the service URL using an AsyncTask<>, then later on get its response into a String object.
And, parse it, using JSONObject/Json Array present in android. You will get many examples for this.
Later on you can create a String array, load your data in it, and set it for auto complete for text view.
Here is an example for this.
String[] listTeachers; // initialize this with teachers JSON data
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.layout_teacher_list, listTeachers);
tvTeacher.setAdapter(adapter);

Android: How to get meta data of a particular mp3 song [closed]

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 know that the songs artist,album etc can be displayed by using MediaStore.Audio class. But it displays the list of artists,albums etc. The problem is when I click an artist name(displayed as list in my activity), all the songs with that particular artist should be displayed.
How can I filter the songs based on meta data (album/artist etc). How to get metadata of that particular song ?
If you want to filter based on the artist that the user clicked, you need to requery the database.
Below is an example of such a query.
String query = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND _display_name LIKE '%.mp3' AND artist LIKE " + artistStringHere;
Read through the mp3 and find the id3 and id3+. However, dealing with mp3 music usually indicates piracy.

Categories

Resources