logical problem in an android app - android

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......

Related

How would I go about displaying data from an API website and putting it in text format on an activity page?

I want to show data in a sensible form for my movie database app. The website I am using to extract data from is www.omdbapi.com. I have already created a code that extracts the title and year of the movies and displays it in a ListView form which contains items that are all clickable to another activity. I would like each activity that the ListView item clicks to to display the movie information under different headers etc.
I have been stuck on this issue all day. I'm new to coding and have no clue what most processes are called etc. Im not asking for the entire code, just instructions on what to do because I am stumped. I would be very very grateful.
Thank you.
Depending on the format the response is formatted you would either use (probably) an xml parser or a JSON parser and grab the info between specific xml tags or the specific keys within the JSON output.
There are thousands of examples of both methods. If you can get the title to display, then you already know how to get the other elements.

Android - how to create custom word dictionary for only my application?

I have successfully added a word to Android's predefined user dictionary, but i want to create a custom dictionary which can only be accessed by my application.
For example: When i type "lol", the suggestions show me "laugh out loud" but when I want another meaning of "lol" then I can manually add another meaning of "lol" (eg, "xxxxxx" - so the next time the user writes "lol" in an EditText, the suggestions will show him "xxxxxx").
No other application should have access my dictionary data.
I have worked with spell checker class but it gives me only correct word and I can't my own word meanings.
Please give me some suggestions or links.
There is an Androids inbuilt class UserDictionary so that you can add your spells programmatically into that, Here is a link you can go through with , and which may relates to your problem .(In this solution nidhi has manged programmatically to retrieve data back)
Add word to user dictionary and retrieve them back from dictionary
In addition you can go through following links to :
http://developer.android.com/reference/android/provider/UserDictionary.html
http://developer.android.com/reference/android/provider/UserDictionary.Words.html
Moreover if you want a custom personal dictionary then manually you have to store words and retrieve them back .
Hope that helps !!!

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

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.

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.

Conceptual help with Android ListView

I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like to move up to a real ListView, but I'm just not finding the sample/explanation that I need to take that next step.
I have successfully reproduced the HelloListView sample, starting with the hardcoded string array, and moving to a string array defined in my res/values/strings.xml. I've taken one small step toward my goal by adding my HttpClient code to retrieve a set of data from a service, parse the results into a String Array and feed that into setListAdapter() such that my text and links show up as text-only in ListView items.
I want to move to the next step which is to make each "row" in my ListView launch the browser to the URL contained in the data, either by
(A) clicking anywhere in the row, or
(B) clicking a hyperlink displayed within the row data
For option (A), it appears that I need to have my onItemClick() method issue an intent that launches the browser. That's straightforward, but I don't get how to associate the URL with the item (currently its just one part of the string content for each "row" of text). How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL? Do I need to replace my String Array with an array of custom objects?
For option (B), can I use Linkify? It seems that my string array elements get converted to individual TextViews (inferring from the way the Toast text is generated in the HelloListView sample). Do I have access to that TextView to run Linkify against? Do I need to replace my String Array with a TextView Array and run Linkify myself? Am I completely off base?
Thanks to anyone who can help explain back to me what I'm trying to do, in a way that helps to find my way around the SDK, samples and other helps!
How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL?
Use a regular expression (java.util.regex) to find the URL.
For option (B), can I use Linkify?
Yes.
Do I have access to that TextView to run Linkify against?
Yes. Override getView() in your ArrayAdapter. Chain to the superclass and get your TextView from the result of super.getView().
Even better would be to use Linkify on your strings before putting them in the array in the first place.
Do I need to replace my String Array with a TextView Array and run Linkify myself?
No, and that is really not a good idea. Here is a free excerpt from one of my books that goes into more detail on tailoring the individual rows of a ListView, in case this helps.

Categories

Resources