android textfield programatically based on data - java

I am Having a trouble. In my project i am having a spinner . Each value i will select in spinner it will make an api call which in return is receiving various objects array.
Important : Each value in spinner will get data from api consisting of different array length.
What i want is to display that each value of array in a spinner .The thing is i am not finding any way to create only that amount of spinner which are equal to data in array.
Example :Spinner value is 1 and array we get from api call has 3 values. Then if spinner value is 2, array we get has 5 values. I have to create 3 spinners if spinner value is 1 and 5 spinners on layout if spinner value is 2 automatically.
Note : Array values can go upto 15 .

Use a RecyclerView for dynamic content. When you get different array from api change you Adapter data source and notify for Adapter for data change .
Check the link i provided, there is a Adapter class called MyAdapter. You just have to update mDataset String Array and need to call notifyDataSetChanged. Adapter will automatically update its resource.

I would suggest you just create one textview and use StringBuilder.append to append all values from the array with proper styling (meaning commas etc)

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.

can i delete array of listView but not update listview?

I spent some time to google it, but didn't help.
I have a listview that contains an ArrayList.
Can I collect all data in array, show it in listView and delete array, but not update listView - so data will be on screen?
Yes until you scroll the list view to next visible item (or call notify item set change), then ListView ask adapter to provide object for example at 5th position and you will get ArrayIndexOutOfBoundsException or NullPointerException. So if you want to avoid that you have to copy your list elements to another ArrayList instance and pass it to your adapter.
arrayListMain.get(position).remove(arrayListChild.get(position));
notifydatasetchange();
arrayListMain is which arraylist your are use at setAdapter and arraylistChild is arrayList in your adapter

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

Android Spinner value retrieved from database and dynamic selected item

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

Change the text in a listview base adapter

I have a custom baseadapter that i use to populate a listview. each row that populates contains 4 text views in it. How can I change the text of one of these views without having to repopulate a brand new array into the adapter?
Just change the value into the array and call this method
youradapter.notifydatasetchanged()

Categories