I am creating an app that has several Buttons on the first screen. Every Button will parse a separate XML file and is supposed to create a nested list from that information.
All the XML files have this structure:
<blalist>
<house>
<name>Blaname1</name>
<eaddress>195 bla steet</eaddress>
<caddress>195 bla strasse</caddress>
<telephone>123456</telephone>
</house>
<house>
<name>Blaname2</name>
<eaddress>15 bla steet</eaddress>
<caddress>15 bla strasse</caddress>
<telephone>12345685</telephone>
</house>
</blalist>
After clicking the first button i would like to generate a ListView consisting out of only the names from tag "name". So the list should only show Blaname1,Blaname2...
After clicking on one of the names all the other tags should be displayed as content;
tags "eaddress","caddress","telephone" and three extra buttons.
Basically a 3 screens scenario. First page with the main buttons. Second page shows a list generated only with the names. Third screen shows the details of the specific name clicked.
How do i go about that? I found loads of info for parsing xml to ListView and some info about ExpandableListView but i couldnt really wrap my head around of how to go about this one. Please help!
All you need to do is parse your XML and structure the data in the format that is supported by the SimpleExpandableListAdapter class.
1) For groups
List<HashMap<String, String>> lstGroups
2) For sub items of groups
List<ArrayList<HashMap<String, String>>> lstGroupItems
and then you can use SimpleExpandableListAdapter
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
getApplicationContext(), lstGroups,
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key that will identify group in `lstGroups`.
new int[] { R.id.row_name }, // ID of each group item.-Data
lstGroupItems, // childData describes second-level
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] { "Sub Item" }, // Keys that will identify child items in `lstGroupItems`
new int[] { R.id.grp_child }
);
setListAdapter(expListAdapter);
You can refer this example
Expandable ListView in ANDROID using SimpleExpandableListAdapter, a simple example.
Added :
I think you should use SQLiteDatabase if you are having large amount of data or else you can structure your data in the following format
Map<String, Map<String, String>> mapHouses;
Here the key will be the house name and its value will be again the Map which will hold the house properties and the corresponding value.
You will be requiring access to mapHouses accross diffrent activity so you can have the same in your application context i.e the Application class and pass the house name to the activity that neds to display the house details. But you will end up holding large data into the memory and which can be lost if your application is killed by Android.
Based on your comment in response to Vishal your question is actually asking how to build an entire application.
You need to build
a main activity with a button that launches your list activity
a list activity that displays a list of names
a detail activity that can be used to display the details associated with a name
In addition you'll need to decide on a technology you'll use to deserialize the XML and store it somehow. I'd recommend XStream to deserialize but there're loads of options and you may already have a preference.
Then you'll want to store the Name objects you've deserialized. I'd recommend that you use ORMLite or DB4O.
You'll need a way to load a list of all names and a way to load the details of a particular name from whichever persistence technology you've chosen.
Your best bet is to try and do those things and then post new questions about specific problems you have trying to build the application.
Hope that helps... and isn't just teaching grandma to suck eggs
Related
I'am using StickyGridHeaders for GridView with sections.
this library is using R.array.countries to populate GridView with provided data and extracting first letter from passed string array to create section heading.
I m trying to pass an ArrayList of objects that will contain ArrayList for sections text named as "sectionArrayList" and "contentArrayListPrivate" and "contentArrayListPublic".
Now i want to play a for loop that will play till < sectionArrayList.size and will check is there any sections then show section text and then show all contents associated with this section by contentArrayListPrivate.size and similar for others but unable to achieve my target.
Can someone please point me towards right direction how to achieve this task ?
want to achive something like:
I downloaded it and checked to solve your problem. so here is solution.
First of all that project is replaced to SuperSlim it is showing on your given link itself, so get superslim.
Then follow the example in that project to achieve it. In that example there is a file named CountryNamesAdapter.java open it, in the 37th line there i found this
final String[] countryNames = context.getResources().getStringArray(R.array.country_names);
which means the data is loaded from Array resource
replace it with
your data - convert your arraylist to string array and assign it like this
final String[] countryNames = myData.
II would like to create a scrollable list of items that can be sorted according to different criteria that can be chosen by the user from the action bar; I was thinking of a button that says:"Sort by...". I am working on an Android app.
I am developing a tourist guide, or rather, making an app out of a paper tourist guide I have previously written, thus I have a list of monuments through which the user can browse.
It would be great if the user could sort the items of the list in alphabetical order, or according to the rating of the monuments or on the basis of a tag indicating their type (historical building, museum, etc.).
Would it be even possible to display under the name of each item, like a sort of subtitle, a series of dots or stars indicating the above-mentioned rating?
At last but not the least, would it be possible, only when the monuments are sorted by name or rating, to automatically group them by another tag?
Like in some song player apps, when you choose an artist, you get all of his/her songs displayed often grouped by album. In my case the grouping tag would represent the zone in the city of the monuments.
Despite my experience in publishing, I am a newbie in Android (followed just a few courses) and the API docs made me very agoraphobic about coding. I know I am asking much so I don't demand a detailed explanation but a few suggestions about what could be a solution, a bunch of helpful guidelines and some names of specific API docs about Array Lists and sorting methods I should look at.
Thanks already for your help.
Firstly, you need to have a custom Java Object for a particular item
for example:
public class CustomItem{
private String Name;
private int Rating;
private String Tag;
// getters and setters
}
Then you can create a Listview with Input consisting of a List of type CustomItem. Here is a good ListView tutorial: http://www.vogella.com/tutorials/AndroidListView/article.html
You can then have somethibng like a Spinner, in which you can add the sort criteria. When the user selects one sort criteria, you can sort the Input List for the ListView and refresh the listview by doing: listView.getAdapter().notifyDataSetChanged();
Hope this helps.
I have a scenario here.I am developing a housing app in which the Complex owners can post announcements and flat owners can see it.I am using webservice.The complex owner can add a new announcement(which I am saving in my server) and the flat owners can see those announcements(I am binding the announcements headers into a list view through json parsing and on-clicking a header a full message will be displayed).
Now the problem is in case of new announcements.I want to distinguish between the readed and unreaded messages(just like in our mail).So how can I determine which listview item is clicked or which item is not clicked??And also how can I give them different colors(i.e. to mark an item unreaded or not clicked ??)
Any help will be appreciated.
Save all announcements in a table locally in sqlite. Add a column to contain the read unread flag.
While populating the list read from the table and load considering the flag.
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?
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......