Android Spinner value retrieved from database and dynamic selected item - java

Hi All I need your help.
I am currently having problems regarding to Android spinner.
Well, I have two spinners, one for source language and the other for target language. these two spinners values contain language list retrieved from database. For example in database I have list of language:
language_code(en,kr,jp,chinese), description (English,Korean,Japanese,Chinese).
The first spinner will contain all the language description whereas the second one will contain all except the selected one in the 1st spinner.
if the selected item in the 1st spinner is English then the values in 2nd spinner must be only the rest exclude English.
What I want is the user can change the languages any time they want, so when the spinner value is changed, user have to click a button to trigger the change and then using the intent to pass to the same class but with the different spinner value. And what I want is the spinner selected item for source and target are from the previous selection.
I have done with the spinner but I have idea with the dynamic change. Any idea?
Thank you

Related

Spinner inandroid studio

I have 2 spinners and 1 edit text. How to get selected spinner item. I need to know witch ones are selected, so I could show conversion resoult in other activity.
First spinner have 2 items ( Celsius and Fahrenheit) second also. How to call one of 2 methods depending on spinner item select.
Create a reference for your spinners. Extract the selected value of the spinners like this:
String spinnerValue = String.valueOf(spinnerReference.getSelectedItem());
Considering that spinnerValue can contain either "Farenheit" or "Celsisus", you can use a switch block to call the appropriate method.
If you want to check currently selected item in the spinner you should have an instance of it. If you don't make sure you assign an id (for example "unitSpinner") to it in the layout file and then in the Activity's onCreate method call Spinner spinner = (Spinner) findViewById(R.id.<idYouAssigned>). Then you can call spinner.getSelectedItem() which will return either "Celsuius" or "Fahrenheit" depending on which one the user selected.

Listview filter through same names Android

So I have a custom spinner header, where the user can change the title of names based on selection. What I want to do is if they click on the spinner and change the default, then it only shows the names in the listview from the title of names. Currently I have tried this by reinstantiating my fragment from my tabhost, and if conditions are met it would just remove from list everything that doesnt have what user selected. But this is inefficient and it didn't work as the listview wasn't updated and the condition wasn't even getting called on the new instantiation... Is there any filter way I can do for this? Any ideas or help would be great!
You only need to refresh the ListView not the entire fragment. There are several ways to do this, including providing a different data source to the ListView's adapter. The exact details for how to do this depend on whether you are using an ArrayAdapter or a CursorAdapter.

Android Studio - Passing a title and description through ListView

I have created an activity which I need to update with posts made up of a "title" and "description". Earlier a ListView was suggested as an option but I do not know how to add two pieces of text (title and description) to each individual item of the ListView through a String array.
There is a "new post" button on the feed interface that opens a new activity containing 2 TextEdit boxes for adding the title and description.
When "post" is pressed on this second activity I am trying to move the title and description into an array that updates the ListView on the first activity with a new item containing the title and description stated within the TextEdit boxes.
Any help would be greatly greatly appreciated,
Aaron.
The best possible way to this is by using a data base. Android has a built in SQLite data base. You can store in all your data into the data base and query it to get a key/value pair array, which you can pass to your listView adapter class and get the data you need into the list view.
Hope this link helps you out-
androidsolution4u.blogspot.in/2013/09/android-populate-listview-from-sqlite.html?m=1

Android: when spinner item is selected how to prompt for additional details

Trying to make a checklist type app that when you select an element from a spinner you will be prompted for additional information. For instance if you select apple it will ask you how many and give you an editable text box to select.
Should I design the page so that it uses a new intent after each item is selected and creates a new page with the prompting and previous selections in it?
Or is there a better method?
OnItemSelectedListener and AlertDialog is the way.
1.Use OnItemSelectedListener and override the ItemSelected()
2.create and show the AlertDialog with edittext inside the ItemSelected method.
If you are not taking so many inputs from user then you can create a simple AlertDialog for getting those values on every item selected from Spinner or if there are lot of inputs needed then you should call a separate activity for that.

Update a single spinner in Android based upon the current value

Is it possible to update a spinner based on its current content?
For example, I have a spinner with two values - fruit, vegetables. If the user selects the vegetables option, the spinner will updates its values, and take the new values from a string array, for example, vegetable array containing values potatoes, carrots, mushrooms, peppers. My intention is to only use and update one spinner.
Any advice, hints, tutorials or recommendations would be much appreciated. Thank you.
What you would have to do would be changing the adapter, whether you switched what adapter was being displayed, or just switching out what lists that adapter was using. Once you have changed the adapter, you notifyDataSetChanged(). I'm not sure how nice that will look graphically, but it should do the trick.

Categories