I have a string array that I am trying to populate with Spinner in my android application. What I am also trying to do is that I am saving the selected Item on the device database as well as on Server. However I am converting the data on the server to JSON.
Due to this, the value that I want to save on the server is different from what I am presenting to the user. Just like we do in the HTML. For example I will display ICE Cream to the user. When the user select ICE CREAM, what should getSelected and be saved to the server should be IC instead of ICE CREAM. I have search through but could not get a head way here. I read this post here but did not satisfy my need.
Can somebody please explain to me how to go about doing this. Thanks in advance
How about creating a CustomArrayAdapter for the spinner, and storing the ID in the views tag
view.setTag(MyIdVaraible);
Then when the item is selected in the spinner you can call
//Integer is a example, it can be any type
Integer theID = (Integer) view.getTag();
Related
I'm currently doing a project from one of my subjects in my university. I'm about to do an attendance app that checks if the professors are present, late, or absent in the room based on the schedule. I made an app in an android studio which uses radio groups and radio buttons that will change the text in the text view which will show if the professors attendance status. I'm thinking of making a button that will upload the text views with the attendance statuses to a website which holds the data(database).
I'm not used to programming in the android studio that is why I would like to know if a way to upload the text views on a website. Thanks
It's quite simple, You have to create Weg api that you can call from the android mobile application and pass the current status of the professor or the whatever you want to pass on the server. That api will update the database as per whatever you have passed from the mobile application.
Also, One more thing that you can not pass the text view, you just need to pass the text of that view.
I hope, you will get answer from this.
Happy coding...
Assign value of textview to a string variable.
And use this string in your api to pass data.
For example if you have a textview with name teacher, you can get its value using this line.
String st_teacher = teacher.getText();
Now use that st_teacher value in your api to upload data.
I just created a spinner and make this spinner read from the database. and display them in the spinner. I already did that. But I want to right down the Id of the selected item.
for example : when I select the first raw called (1, tyat abdullah, sergurey )
I need the Id (1) only to be written down without the full record.
I need the Id (1) only to be written down without the full record.
Then when you are doing labels.add, only put the data you want to see
You can also use doctorsList.get(position) within the selection listener, and set the other text view accordingly.
For example, doctorsList.get(position).getId() seems to get the information you are asking for
simply use this to get the selected item index
int index = spinner.getSelectedItemPosition(); //this will give you the seleected item index
is that what you want ?
leme Know :)
How to set the string values on spinner prompt?
The process how I am doing is:
I am able to retrieve the json data(it has only one single value), so I am getting the single text with the help of String.
Later, I am trying to set the string value in Spinner prompt
SP_gender is called as Spinner here. In String gender1, I have texts called as "male"
String gender1 = i.getStringExtra("bundle_CusGender");
SP_gender.setPrompt(gender1);
System.out.println("Check bundle_CusGender = : " + gender1);
When I try to print this, I am getting a value as male
System.out: Check bundle_CusGender = : male
How should I set the single text in spinner Android?
Firstly the setPrompt() methods documentation states:
Sets the prompt to display when the dialog is shown.
Which is pretty vague but internally it calls the setPromptText() method which sets the description on the popup and has the following documentation.
Set hint text to be displayed to the user. This should provide
a description of the choice being made.
So if I am understanding your question correctly you want to set the spinners selected item. You should be using either setSelection(int) or setSelection(int, boolean)
For those to work you would need to give your spinner an adapter if you haven't already. If you don't know how you should check out this answer which explains in more detail.
Currently I have been stuck in the implementation of the search item json Url logic. I have TextWatcher code but I do not know how to implement to search an item that user input in the EditText.
I want once the user start typing the search will be triggered and search dynamically, and once the user hits on the DONE button on the Keyboard the string in the EditText will be searched automatically
How do I implement this ? Or is there someone with a better idea?
Please provide examples...Thanks in Advance.
It is good if you can save your json data to local storage using mysqlite or you can also use ArrayList for storing your json data.
download all json data on OnCreate() method of activity.
store it to ArrayList.
Display it to ListView by setting up adapter
When textchanged in EditText create new ArrayList and set again adapter with upgraded list of data.
hope this may help you.
I'm programming an Android app that shows data from MySQL database via ListView with some sorting:
1) Items that are closer to android phone by GPS are shown firstly
If there are 2 or more items with equal distance, second sorting parameter applies - time.
2) Items that are closer in time are showm firstly.
Here is a scheme of the process that I guess to implement:
My idea is to get all needed rows into Array, then make some PHP manipulations with it and then pull sorted Array to the phone.
(as shown on the image above)
So please advice me what will be the proper way?
Maybe there is easier method for this functionality?
Or maybe I should do all the sortings exactly in the Android app when programming ListView, getting only standard "SELECT *" array from the database? Then, is there an opportunity to create a ListView with sorting based on calculated values?