I found this tutorial which makes exactly what I need :
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
The problem is that the ListView gets populated from an XML found out on an URL. What I have to change so I can load the list items (Image+Text) from an internal XML ?
What do you mean by "internal" xml?
Is your XML file on the SD card or is it compiled in to your application as a raw resource?
Take a look at these links :
Reading an .xml file from sdcard
Android : Reading XML from local resource (for testing)
The line in your code that you will need to change is :
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Related
There are a couple of audio mp3 files in res/raw which go as prepacked audio files for the app. They all have proper names ...must contain only [a-z0-9_.] which do not look nice when parsed inside ListView.
I see many apps have their custom names for audio. For example, raw file name is "default1" and custom audio name is seen as "The Morning Shine".
How can I set custom name for all custom audios in res/raw?
If these files are static and prepacked as you say, try having an xml resource file that holds custom Strings for each file.
I don't know how you are managing your List, but with a custom Adapter you can link the proper name based on the resource ID.
Other way that maybe could help you is read the Tags directly from the files, with the Class MediaMetadataRetriever.
Example:
MediaMetadataRetriever retriever=new MediaMetadataRetriever();
retriever.setDataSource(yourFilePath);
String songName=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
You have other constants like METADATA_KEY_ARTIST, METADATA_KEY_ALBUM and so on for the other fields.
See: http://developer.android.com/intl/es/reference/android/media/MediaMetadataRetriever.html
Don't forget to call retriever.release() when you're done to free memory.
Good luck.
I am loading a XML Parsing files and getting its data on a listview. I want to know is there any way to load images from Local SD Card or application instead of loading it from the Internet URL.
XML file i have like this :-
<id>4</id>
<title>Lesson</title>
<artist>English</artist>
<duration>4:23</duration>
<thumb_url>https://abc.com/apple.png</thumb_url>
Want it to change like this :-
<id>4</id>
<title>Lesson</title>
<artist>English</artist>
<duration>4:23</duration>
<thumb_url>R.id.apple</thumb_url>
I am trying to read data from an xml which is stored at sdcard.
So, I used XmlResourceParser in my code but how can I provide my xml file to XmlResourceParser?
Is there any other way to do the same?
File myXmlFile = new File(Environment.getExternalStorageDirectory()+"/myfiles/myxml.xml");
And try to read data from File...
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.
i am developing one application for displaying images and labels and its sound.i want to get this info from xml .where i need to keep xml file in android project how to get values from that xml file
Thanks in advance
Aswan
You can package the xml file in assets/ directory inside your apk. With that, you can use
AssetManager assets = context.getAssets();
InputStream in = assets.open("myfile.xml");
If your file just contains labels, or strings, you can save it in put it in res/values/strings.xml inside your apk. In this case you can access the string values using the android generated R class
If you have a custom file (with custom structure) you can use DOM, SAX, or Xml Pull to read those files. e.g.
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);