I am realy new to android, but I am impressed with spinners. I just want to know if it is possible to have a spinner (populated with cities) and when user selects a city, then refresh and show records relevant to that city?
I will handle the json parsing and all, but I want to know if it is possible? or is there a better way for city filtering? any examples would be highly appreciated
Yes it is possible. Once you changed the data of your first spinner, store your second spinner adapter with new data and then call the notifyDataSetChanged() method of your second spinner adapter.
For example I assume you stores the data in list. Before stores the new data clear your previous data using list.clear() and then store the new data. Then call
spinnerAdapter.notifyDataSetChanged();
I hope this will help you.
Related
I'm having an issue getting the Value of a database entry and passing it to intent.in the following code onItemClick is passing the data of the whole database over as opposed to the item clicked. How can I specify to only pass the data of the item clicked over?? Newbie to Firebase so im at a loss, any help greatly appreciated
This is not the right way of getting data:
String title = putData.child("title").getValue(String.class);
You cannot call getValue() method on a DatabaseReference object. In order to get data from the database you need to attach a listener. Everything in Firebase is about listeners. So you should do the exact same thing that you in your first lines of code.
What I want to create
I want to create a list where each item in that list is an data table like below: The user needs te be able to sort items in the data table and needs to be able to sort the data tables itself.
Each table is going to represent a client and each item in that table is an order. The user will then collect the orders, if he collected an order the order wil dissapear but the user is also able to bring them back.
What I tried
I tried to put a Recyclerview inside a Recyclerview but this caused unitended side effects and bugs, also I read online that it is basically a bad practice. My initial intention was to use a recylcerview with a sortedlist.
I did some searching online and a lot of people recommended using categories between items so that you only need one list. But because I have data tables (CardViews) that can be independent sorted this isn't an option.
If anyone want to give me a nudge in the right direction, I would be really thankful.
What you can do you can use recycler view and in custom row check box with 8 text views and when position is 0 inflate categories like fat, calcium etc and after that position populate data and if you want next button which shows next items in list use fragments or pagination that should do the trick and you can achieve this using single recycler view. You can also use header to show categories.
I'm kinda new to Android Programming. I'm trying to create a list of several objects. Each list item should look like this:
_________________________________________
| Title Text View | Edit |Delete|
| Secondary Title Text View |Button|Button|
Each list item represent an object which was read from a database. My question is, how do I keep the list dynamic according to additions, edits and deletes, which the user can perform?
I thought about reading the database into an array and then using array adpater, and when the programs finishes, writing it back into the database, but I cannot match the objects' fields into each text view (or atleast I don't know how).
I'm sorry if my question seems stupid, I'm really new to android.
I think what you want to do is create an adapter which holds the data that you got from the DB.
The data will be displayed using a ListView (this is the part that will display your attached sketch).
After you change the data in the DB, you should refresh the adapter using:
yourAdapter.notifyDataSetChanged();
So your ListView will reflect the changes.
I am attempting to create a list view which displays different data based on a selection from an a spinner.
My list view is implemented via a base adapter which works fine.
My data is stored in an array list of objects which each contains fields that store individual data and based on the selection from the spinner filters the data stored in the array list and displays it on the list view.
But my question is how can I clear a list view content without clearing its underlying data (stored in the array list) and calling notifyDataSetChanged? I want to be able to preserve the data stored so if the user goes back to a previous selection, the data is still present.
Thank you for your time in reading this.
As your data is stored into an ArrayList, you can simply use:
listView.setAdapter(null);
It will remove the adapter of your ListView, and so, remove all the items displayed.
The data will still be in your ArrayList so if you want to re-display this ListView, you just have to recreate your Adapter and set it again. You can even create a global instance of your BaseAdapter so you only have to create it once.
You could just pass another ArrayList to the adapter with the new data to show inside the ListView.
Or, you could create two ArrayList inside the Adapter, one named original which contains the original elements of the ListView and another currentElements which will be the real ArrayList to show changed as you want. With some custom methods, you can choose to switch between the two versions of the ArrayList.
It's could be the same concept of an Adapter which implement a Filter.
Anyway if i understand your problem, you want to change the content of a ListView based on the selection. Well, in this case i would send another ArrayList to show.
Create a list of adapters, one adapter for each selection. Then simply switch to a different adapter when the selection is changed with listView.setAdapter(adapter)
Im trying to make an android-app that shows a list of albums and it displays the album-title on each listitem. So far so good.
But I would also need the album-id somehow connected to each listitem to use when I get the next level to list (the album-tracks). How can I in each list item store more values for the items then the displayed text (album-title)?
Right now Im using an ArrayList (to store the album-titles) that is connected to a ArrayAdapter wich use the simple_list_item_1 layout. I get the album-info (title, artist, id) form external xml.
I was thinking on using a multidimensional array but I don't know how to connect it to the ArrayAdapter since it only is expecting an array?
Any suggestions on how I should tackle this?
Instead of using simple list adapter you should use android custom list view.
Check out this link
Hope this will help you.
try Android sample demo project
http://developer.android.com/resources/tutorials/views/hello-gridview.html
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/index.html