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.
Related
My task is to develop a list of different type of questions, a survey. It could include types like Integer-Answer-Question, Long-Text-Answer-Question, and so on.
Why is it needed to be a list? Because for the people using the app is way better to scrolldown answering each question rather than swiping to right, or doing another movement.
So I was face to face with the dilemma of using a ListView or a RecyclerView. My research gave the final outcome of using a recyclerView and having a viewHolder for the different types of questions that I have.
The struggle came when I realized that there is a type of question that has dependency related to it; how so? if you select one option then you have to "show" some questions, and if you deselected this option then you have to "hide" it again.
The thing is that I need to know the reference of each question to their viewHolder in order to "show" o "hide" each of them, but if the recycler is recycling viewHolders then it could create a mess on my logic.
My punctual questions are: Am I using the correct component with the RecyclerView?, is there any way to access a viewHolder with a unique reference, like and id or something?.
if you need me to show some code, I'd do it happily.
Valuable information:
if you are interest in how notifyDataSetChanged() works you can access to this link for further and detail information.
Minas mina's approach was the correct one!
If I understand correctly, you need to hide some types of questions when the user selects an option.
Your understanding of what the view holders are supposed to do is not quite right. The view holders cache a bunch of views that you later use in onBindViewHolder() to fill-in data from your model objects.
The actual model objects should be in your adapter. In your case, something like
List<Question> questions
In onBindViewHolder(), you fill-in the fields of the View holder with the data from a Question object.
As for your question, what you can do is to set a flag in your recyclerView adapter, e.g. hideQuestionsOfTypeA to true and then call notifyDatasetChanged() on the adapter.
When binding objects, check if that flag is true and if yes, set the visibility to GONE to the views that need to be hidden.
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.
Ive got some gridView and some function which is called when a message arrives from server. In this function I get the values from server and I want to write this value in specific item in the gridView.
The problem is I dont have any idea how can I rewrite text of som Item in the gridView and I couldn find any answer on the internet :/
First you need to to add the received data into arraylist which you used to populate your grid view . You can add the received data into any position of arraylist as you need.
Then update the Arrayadapter using the following command
adapter.notifyDataSetChanged();
I understand up to some point. In my expatiation i think your set by using adapter right. So the simple solution is once you get the new items for a grid. call the setadapter again. Then that will set the new items. Try it once.
Actually i have to comment out but i don't have that much points.
I have started to manage the Points and Details of a sport competition. I have displayed Competitor's ID and Name from Database. But i need to Get the Points which they got at run time Dynamically.
And the List of competitors must be changed Dynamically for verity of Games. There are Various games like Tennis, Chess, Running and so on..
Every Game that contains different Players and different no.of players. Can we Use this with ListView?
I need to solve this problem of Giving the points to the Competitors..
You could use the listView.setAdapter(); to set the data on the listView. Also, you could add a TextView as part of the implemented getView(position, converView, view) and return it to the listView.
You could also have a tableLayout inside of the listView. You would have a seperate layout.xml file for the tableLayout. This would have 3 columns. And return this as part of the getView() method.
You Can use the ListAdapter with TextViews and Data place holder
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