in my app i am sending when i click a button it goes on to a url and it returns back an xml file. The xml file is as follows
<search>
<data>
<userid>1</userid>
<name>Jean</name>
<address>dbvsvksn</address>
<dob>Mar 3</dob>
<country>us</country>
</data>
<data>
<userid>2</userid>
<name>Anne</name>
<address>dbvsvksn ,</address>
<dob>Jun 2<dob>
<country>us</country>
</data>
<data>
<userid>3</userid>
<name>J</name>
<address>dbvsvksn ,</address>
<dob>Dec 6<dob>
<country>us</country>
</data>
</search>
From this xml file i am listing out the name's in a list view in an activity. In the list view when a name is clicked it moves over to a new activity where i want to display the correct address, country and dob.
I am able to get the xml file and list out the names in a list view, but i don't know how to display the exact tag related to the name selected , please help me. How to do this....
You say you can get the xml file and list out the names, so you apparently are parsing the xml. Are you using one of the XML parser classes (DOM or SAX)? If so, presumably you are building some sort of data structure based on the parsing (probably an array, judging from the XML fragment you posted). Use the index of the selected name to index into the array and retrieve the rest of the data you need.
Perhaps if you posted some code showing what you've tried, we can provide more specific help.
you can use textview. The number of userid's is there same number of textview.One for each userid,name,address,dob & country. Just add these in tablerow & just check which row is clicked just pass all information of that click in intent & you are able to display all info.
Related
Want to populate the spinner from the online XML data which i am getting from link for example-http://example.com/abc.svc/APIGetalllocationAgentID=1234&KeyCode=123456789012345677544
From the above link assume I am getting the below pattern of XML
<a:Cityvalues>
<a:FromCityId>123</a:FromCityId>
<a:FromCityCameIdName>Cityname</a:FromCityCameIdName>
<a:ToCityId>321</a:ToCityId>
<a:ToCityNameidName>Cityname</a:ToCityNameidName>
</a:CityValues>
From the above XML value format which i am getting from the link..want to fill the spinner of android of tag <a:FromCityCameIdName>Cityname</a:FromCityCameIdName> i.e the spinner should display Cityname
Before set it in spinner you require to parse it. Following is the url which help you how to parse xml data ?
http://www.tutorialspoint.com/android/android_xml_parsers.htm
https://developer.android.com/training/basics/network-ops/xml.html
http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/
I have an AutoCompleteTextView in which I have to show suggestions from data in an XML file. Is it possible to do so, or will I have to convert this XML into JSON format?
Structure of my XML file-
<?xml version="1.0" encoding="utf-8"?>
<elements>
<elem>
<name>Name 1</name>
<code>2001</code>
<dat>1001</dat>
</elem>
<elem>
<name>Name 2</name>
<code>2002</code>
<dat>1002</dat>
</elem>
.
.
.
<elem>
<name>Name 3</name>
<code>2003</code>
<dat>1003</dat>
</elem>
</elements>
The program has to look for matches in all three fields- name, code and dat.
AutoCompleteTextView needs an adapter that will supply the data and the views. You should parse the XML file (by using an XML parser like SAXParser, etc) and convert it into an ArrayList of objects and then use the ArrayList as the backing data for the adapter.
XML or JSON depends on whether or not the data will be modified. XML is good if the data will later be modified by the user. JSON is good for keeping snapshot data that will not change.
This is my first post here :-). I am developing an application for android in eclipse.
My question is I have put an XML file in sdcard with some elements like id,First name and lastname.
Form my UI i have one textbox and button. User will enter ID in the textbox and on click event of button I should fetch the data based on that ID. and display in TextView.
Any help please??
Thanks in advance. :-)
Here is a sample of XML file which is given to me,
<tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>1</ID>
<LastName>Family 1 (1-42-167)</LastName>
<OtherNames>FamMem1</OtherNames>
<DOB>01-01-85</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
- <tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>2</ID>
<LastName>Family 2 (1-4-16)</LastName>
<OtherNames>FamMem1</OtherNames>
<DOB>01-01-85</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
- <tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>3</ID>
<LastName>Family 3 (1-4-16)</LastName>
<OtherNames>FamMem3</OtherNames>
<DOB>01-01-98</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
SO is it possible that somehow I can pass an ID as a parameter and I can just display the rest of the information like name and dob etc on my screen?
Here is a complete example with source. You just to get the File using
File file = new File(Environment.getExternalStorageDirectory()
+ "your_path/your_xml.xml");
Then do the further processing.
If you need example for different types of XML Parsers you can download complete example from here.
I have been working on android for about 4 months, i am working on a simple application to download a xml file placed on local server to the sdcard. I have done this part successfully, now i want to edit the data present in that xml. To get a more clear picture here is a sample code of my xml file ...
<seekbar>
<value>
50
</value>
</seekbar>
now am reading the value 50 by xml parsing and updating the value of seekbar as 50. Nowi change the value of seekbar to 100 through GUI. So when i click on save button i want that the value 50 should be replaced by 100 in the xml present in the sdcard. I have learnt about the sdcard permission but i am not getting about how to go for this modifying part.. Will i have to parse the whole xml again...??? Please help guys....
You can load the xml into a DOM Object. modify the value or value node and write the new DOM object back to the file.
in my app when i click a button it gets an xml file from an url and it moves to a new actvity B. In activity B i have a list view, where the tag "name" are been listed out.
My xml file is as follows
<search>
<data>
<userid>1</userid>
<name>Jean</name>
<address>dbvsvksn</address>
<dob>Mar 3</dob>
<country>us</country>
</data>
<data>
<userid>2</userid>
<name>Anne</name>
<address>dbvsvksn ,</address>
<dob>Jun 2<dob>
<country>us</country>
</data>
<data>
<userid>3</userid>
<name>J</name>
<address>dbvsvksn ,</address>
<dob>Dec 6<dob>
<country>us</country>
</data>
</search>
when i click on any item on the list view it opens a new Activity C. Here in a text view i want to display the name i have clicked in the previous activity and i have to show the address, dob, country of the name that been clicked.
Now i have listed out the name's using Sax parser in activity B and using intent i have printed the name in activity C but how to get the other related tag's.
please help me...
I think you should make a class Users containing fields like id, name, address, dob etc with their setter getter method. and when you receive XML, parse it using DOM, and save their values in array of Users Object. By this you can access every field by just calling getter methods. You can pass that objects to other activity, or access them anywhere if they are static.