Source code analysis of jamendo open-source online music player (III)

Source: Internet
Author: User

3. asynctask

New newstask(cmd.exe cute (void) null); execute an asynchronous task without passing any parameters. Asynchronously load the information of a recording and call the corresponding API. The following describes the API. After Successful loading, the gallery of the recording set is displayed. Each item in the gallery is a custom imageview, this imageview can asynchronously load the album image and cache it according to the URL, that is, Com. teleca. jamendo. widget. remoteimageview, which will be detailed later. If loading fails, Retry is displayed, and the toast prompt is displayed.

4. Adapter
Fillhomelistview () in the onresume () method. This is the method used to fill the listview. We can see that there are two different la s in the listview, one of which is similar to the delimiter layout, one is clickable menu items. First, analyze the adapter of the menu items that can be clicked.

The com. teleca. jamendo. Adapter package is an adapter-related class.
Let's take a look at arraylistadapter first. java, which is inherited from baseadapter. The dataset in this adapter is placed in the arraylist <t> MList. The subclass inherits it and overwrites its own getview () method. The program can use the adapter. setlist (arraylist <t> List) or adapter. setlist (T [] list) fills in values of specific types.
The menu items that can be clicked are a subclass of arraylistadapter: purpleadapter, and the filling type is <purpleentry>. purpleentry contains the drawable and text of each row and the operations triggered after clicking.

The following is the overall adapter of the entire list that includes the separator: separatedlistadapter.

SeparatedListAdapter separatedAdapter = new SeparatedListAdapter(this);separatedAdapter.addSection(getString(R.string.browse_jamendo), mBrowseJamendoPurpleAdapter);separatedAdapter.addSection(getString(R.string.my_library), mMyLibraryPurpleAdapter);

We enter separatedlistadapter to check the constructor. First, an arrayadapter <string> headers is initialized. This is the adapter of the separator. addsection (string section, adapter) is the value filled with headers, at the same time, put the two purpleadapters above into the map, and then look at the getcount () method, you can see the total number of items in the listview, that is, in addition to the number of the two purpleadapters above, but also add two separators. Next, let's take a look at the getview () method. When filling in, it mainly calls the getview () of headers and each purpleadapter.
The getview () method of is mainly logical. It should be okay to follow the process carefully.

The following describes three overwriting methods:

public int getViewTypeCount()public int getItemViewType(int position)public boolean isEnabled(int position)

It doesn't matter if you comment out the three methods, and the program can run the same way. The first two methods are mainly used to cache items in listview and analyze the source code, in the setadapter () method of listview, there is an mrecycler variable. You can see its annotations. This variable is used to cache the view and avoid re-create at next layout. Mrecycler is an internal class of the parent class abslistview of listview. Next, mrecycler. setviewtypecount (madapter. getviewtypecount (
); The getviewtypecount () method is called here. In order to initialize this arraylist for cache view, when listview fills the item, it will call mrecycler. getscrapview (position): This method calls the getitemviewtype (INT position) method, obtains the cached view based on the returned type, and passes it to convertview in the getview () method of the adapter, this allows reuse.

Return to the program. The getview () in this adapter does not use the cache view to determine whether convertview is empty. Instead, each view is directly generated, so here the two methods are overwritten mainly for the service isenabled (INT position). This method is used to determine whether this row can be clicked. The headers used for separation cannot be clicked. Of course, if you comment out the three methods, the headers will be able to click and there will be no errors. Return to the fillhomelistview () of homeactivity, and finally mhomelistview. setonitemclicklistener (mhomeitemclicklistener); sets the click event of listview. If you click the separator headers, the program will try this exception, so it's okay. If you click it normally, the method in the previously set listener will be called.

Next, we will analyze the music API.

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.