Search data from a csv file and put it in a spinner - android

I'm new at android programming and I need some help..
In my main class I have 2 spinners. One for countries and one for cities. In the first spinner, the user can choose a country. When a country is selected, I would like the second spinner to show the corresponding cities. To do that, I have a .csv file, with countries code (1st column) and cities corresponding (2nd column).
For example, in the first spinner, the user selects CUBA (the corresponding code is CU). Then I want my program to look into my csv file all the lines with "CU" in the first column and take the cities corresponding and print them into the second spinner so that the user can choose a city of Cuba.
My problem is that I don't where I have to put my csv file and how can I program my application to look into it and print my data into the spinner...
Any help would be appreciated.
Thank you

You should create a Service or a Worker Fragment to do all the heavy lifting: open csv, read countries and cities and filter cities given a country. Then create a callback to the Activity showing both spinners to update the UI accordingly. The following components are needed:
1 FragmentActivity to show the spinners. Should have a callback method to receive data updates.
1 Worker Fragment or Service for reading file and broadcasting updates to the FragmentActivity containing the Spinners
Hope it helps.

Related

how to use a list item to call and display a string in another fragment

i am a novice in android and i was trying to make an application that has two fragments, one with a listView with topics which when one is clicked it opens a topic description in the other fragment. i would like to know how to also store the large string for the description
If the data is dynamic you can store your topics and desciptions in a sqlite database. You have several possibilities:
You load the topic and description at the start and give over the description with a method or an interface to the second fragment.
You store the data in a database and give every entry a unique id and use a method or an interface to communicate with the second fragment and put the id to it. And then you use the id to get the description from database.
UPDATE #1
You can use arrays in your resource files. Create two arrays. One with your topics and the other with your descriptions. But the topics and descriptions have to be in the same order. For example the description of the second topic have to be on the second position in its array. Now you use the first array for your listview and the second(with the descriptions) in the description fragment. The "setOnItemClickListener" method of the listview have the position as a parameter. This is the same as the position of the topics and desciption in your arrays (when you dont resort anything).

Android: different objects in one list

I am a new to android developing. I am developing an android app for a shopping mall...
i want to have a screen where a list is displayed. Name of the mall and its photo should be displayed in the first section with its short one line address...
In the next sections the products should be displayed in the same way....
Product photo, Product Name and its price...
Please suggest me what topics should i read to create such a screen....
could fragments be used to create this screen???
Thanks in advance...
There are many ways. Like you can create a Customized List view for each screen. You can first create an Array List of objects of MallClassPojo. Like:
ArrayList<MallClassPojo> mallList.
Where your MallClassPojo contains the getter setter methods for Mall name,Mall image url or resourceID and short description of mall. Pass this mallList to your adapter class. Retrieve the details and show them in your customised List View. The next screen can be prepared in the same way also.
Well then you can create an Array List of JSON objects. In a JSON Object you can add different data like in one object you can add the company data and in another you can add product data. Isn't it?

Adding new lists within app inventor app

I'm having a bit of awkwardness in App Inventor and lists.
I had hoped to generate a list for a user entered value.
For eample - a text box the user enters Book title, publication year, author, and ISBN.
I would like to create a list with the ISBN as list number.
How feasible/practical is this?
Add items x,y,z to (previously non-existent) ISBN list does not work.
I'm currently trying a working around with empty lists List1, List2, etc that are filled sequentlially but this is less than ideal.
This is very feasible/practical. You have to use 2 lists: listISBN which stores your ISBN and another list, let's call it listDetails which stores sublists of the detail data. To save the data, use two add items to list blocks, see screenshot:
To select the items from your lists, use the same list index together with select list item blocks.
More about lists here, also see chapter 19 here

Android App , add a favorite quote functionality

I have an android app which displays quotes and have navigation to go to next quote and so on. would like to add "Save Quote As favourite" based on users selection of particular quote.
Once user saves Fav quotes and wants to see those quotes only, app should show those quotes.
Currently app reads the quotes from XML file. Let me know if any more information is required to understand the problem.
I would provide every quote with an ID (int). Whenever the user selects a quote to be a favourite, that ID is saved to a Set of integers. Later on if user decides to show favourites, you fetch all quotes with your IDs from the Set and show them in a appropriate view, for example a ListView
If you have a Quote class or something like that, you might as well put them in a collection whenever user decide his favourites, and show them in a ListView with a custom adapter.

logical problem in an android app

hi i would like to know solution for such a problem..... i have an xml file containing users data of around 1000 users listed out in alphabetical order. The xml file use to be as follow
<usersdata>
<user>
<id>1</id>
<firstname>A</firstname>
<middlename>AA</middlename>
......
......
</user>
<user>
<id>2</id>
<firstname>B</firstname>
<middlename>BB</middlename>
......
......
</user>
........
........
</usersdata>
Now from the above xml file i am parsing all the tags and storing them in an array list for each tag. I am listing out the Firstname in a listview, by array list of first name. When the any of the list is clicked, it opens up a new activity where the all other details of the selected name is been shown.
For example if third name in the list is clicked, by using its position(example 3), in the next activity i am listing out the third values stored in all the array lists i am using. This is what currently i am doing.
Now the problem is i have a edit box above the list view, named as a search box. If the letter S is typed in it, then all the names starting with S gets listed first. Opening the next activity by clicking the list now gets some wrong data, how to avoid this.
Please give me a suggestion....
For example if the first name C is clicked, it will be listed at position 3
There is a quick and dirty hack: you can store user id in the invisible field, retrieve it on click and use it as an argument for the second activity. I'm afraid I can't come up with better suggestions without seeing the code.
i tried out by setting some flag and by using an example code in developers site. And i am able to list out the data's but this idea does not full fill my apps requirement in the next activity. So i removed the search part in my app.
Sorry for posting such a question here......

Categories

Resources