Android ListView and Adapter get song list from local/network

Source: Internet
Author: User

Content of this article
    • Environment
    • Project structure
    • Demo 1:simpleadapter
    • Demo 2:baseadapter
    • Demo 3:customlazylist
    • Demo 4:customcompletelazylist

This article only gives the demonstration summary, the code is too many, paste out the meaning is not big, own download debugging, click here to download.

In this article, four examples are presented to show the list of songs in a ListView control, a list of songs, including thumbnails, artist names, song names, etc., either locally or in JSON form on the network.

Environment
    • Windows R2 64-bit
    • Eclipse ADT v22.6.2,android 4.4.3
    • Samsung Gt-i9008l,android OS 2.2.2

Why the real machine version so low ~ Ah, recently colleague mobile phone is broken, just bought a house, bank card left 1000, no money, my Android 4.1 mobile phone borrowed ~

Project structure

Figure 1 Project Structure-java package

Figure 1 is the relevant Java package for the demo:

    • Com.example.listviewdemo package, is the main program;
    • Com.example.listviewdemo.baseadapter package, is the main program of Baseadapter demonstration;
    • Com.example.listviewdemo.simpleadapter package, is the main program of Simpleadapter demonstration;
    • The Com.example.listviewdemo.customlazylist package, which is the main program for the Customlazylist demo, and the custom class that inherits the Baseadapte class Lazyadapter , which is responsible for returning each row of the ListView View;
    • Com.example.listviewdemo.customcompletelazylist package, which is the main program for Customcompletelazylist presentation, and a custom class that inherits the Baseadapte class Completelazylist, responsible for returning each row of the ListView View;
    • Com.example.listviewdemo.data package, is a demonstration of the test data used in 1, 2;
    • Com.example.listviewdemo.utils packages, tool classes are here, including file caching, memory caching, loading pictures, network requests, and streaming tools.

Figure 2 Project structure-resources and pages

    • RES/DRAWABLE-HDPI is the picture and icon resource required by the project;
    • Res/layout is the program interface, where Main.xml is the main program interface, and Item.xml is the page for each row in the ListView, which is common to these demos.

Figure 3 Program Master

Demo 1:simpleadapter

The demo directly uses android.widget.SimpleAdapterto add a list of songs (including thumbnails, singer names, song names) to the ListView control.

Demo 2:baseadapter

The demo uses a lower-level, more powerful android.widget.BaseAdapter class, overriding the appropriate method, especially the public view GetView (int position, view Convertview, ViewGroup Parent) method to add a list of songs to the ListView control.

Demo 1 and demo 2, load a list of songs (including thumbnails, singers ' names, song names) locally. The following two demos, thumbnails are obtained through the network, the demo 3 song list information is stored locally, through the connection to obtain and cache the picture, displayed in the ListView control, and the demo 4 is a network to obtain the list of songs JSON, this way more common, in the client parsing Org.json.JSONArray, gets the picture and caches it, displayed in the ListView control.

In addition, the address of the song list is Http://files.cnblogs.com/liuning8023/Android_Music_Demo_json_array.xml, although it is an XML file, but the inside is the JSON format, This does not have any effect on the program, Cnblog does not allow uploading. JSON file.

In summary, the demo 1, 2, compared to the demo 3, 4, only the way to get a list of songs, the results are almost the same. These four demonstrations are gradual, but also the process of my research and thinking.

Figure 4 The results of the following four demos

First: Simpleadapter demo; second: Baseadapter demo; third: Customlazylist demo; Fourth: Customcompletelazylist demo

Demo 3:customlazylist

The list of songs for this demo is saved locally, and thumbnails are obtained over the network. Thumbnails can be external memory and in memory.

Demo 4:customcompletelazylist

The demo song list is saved in the network, the JSON file for the song list is obtained through the network, parsed into org.json.JSONArray, using thumbnail links to get thumbnails, and cached in external memory and in memory, displayed in the ListView control.

Don't forget to add a section in Andriodmanifest.xml that allows Android to access the network and external memory.

Download Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.