How to populate spinner from online XML link data - android

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/

Related

How to reference a string array in XML of Android layout file

The closest I could find on S.O. is this but it doesn't answer it.
It specifies here how to make a resource reference for a string, i.e. #string/string_name but further down under String Array in the documentation, it gives no option under Resource Reference for referencing the string array in XML like it does further up for String.
It's unclear what element you are trying to load the array into...
ListView has android:entries that accepts #array/ resource.
However, I find that adding adapters in the code makes more sense.
ArrayAdapter.createFromResource allows you to use an a String Array XML resource to load either a Spinner or a ListView using R.array in Java code.

u\2022 not displaying in textview that retrieves from json

I had found an answer that we can use bullets in textview by adding u\2022 with the text.
Ref : https://stackoverflow.com/a/3429643/4919237
When i added this code through XML it displays fine in TextView
and When i try to display bullet through json it doesnt display bullet ,instead it displays the text u\2022 itself.
my receiving Json format is
{"description":"\\u2022first one\\n\\u2022second one edited\\n"}
please help me to reslove my problem.
At First , You can check Html.fromHtml & remove one \ .
Html.formHtml method takes an Html.TagHandler and an Html.ImageGetter
as arguments as well as the text to parse.
YourTextViewObj.setText(Html.fromHtml("Your String"));
FYI
Currently android seems support the following HTML tags to be rendered on TextView.
You can set text using Html.fromHtml like
textview.setText(Html.fromHtml(your description));

Show suggestions for AutoCompleteTextView from an XML file

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.

How to remove html tags getting from sqlite database in android?

In my project I am getting data from sqlite database and setting that data to my textviews. But the data which I am getting contains html tags which is looking odd when I am displaying. Can we remove those html tags after getting them from database? Please help me regarding this.
Thanks in Advance.....
you can use html tags instead to remove by following statement:
textView.setText(Html.fromHtml(htmlString));
Download the JSoup library from http://jsoup.org/, and use it this way:
Jsoup.parse(html).text();
This will return a String that you can put in your textview.

problem in parsing an xml data in android please teach me

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.

Categories

Resources