Identify a view used in multiple activities - java

I have a spinner that i use over several activities. In one of them, I have to modify one of the parameters of the spinner. How could i identify from the spinner itself (without passing any extra parameter) the activities where the spinner will be inflated?

Depends a bit on your app - but I see 2 approaches for now:
1 You could add a tag to the spinner
2 You check the context of the spinner

Related

Is it possible to have as a adapter an FragmentStateAdapter, which will display different data for 3 different fragments?

In short - I'd like to ask, if it is possible to use the FragmentStateAdapter for let's say 3 fragments, but every single one has it own RecyclerView, so every single one will need different data to display. For now, I've just setup some basic TabLayout for these fragments, but Im not sure how would it work.

Switch Tabs with a RecyclerView

I'm relatively new to programming and I'm facing the challenge of having 2 tabs in my activity. In each tab there should be a RecyclerView which is identical with the other.
My guess would be to update the datasource when the user switches the tab. So one activity with one RecyclerView cares about two tabs.
But as I read more and more about it people usually use fragments for each tab.
Why? Which approach is better?
If you use fragments, you have two lists so you can properly implement dragging between pages, and returning to either tab will properly keep current scroll. You can also keep data for each tab in separate fragment, which breaks down huge source files into something more manageable.
Tip for using multiple RecyclerViews with same item types is creating single RecyclerView.RecycleViewPool and keeping reference in activity to reduce number of ViewHolders you need to create.

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.

Can i change the value in a Text field on listview

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

Categories