Improved the music player 2.0 and the music player 2.0

Source: Internet
Author: User

Improved the music player 2.0 and the music player 2.0

Compared with the music player 1.0, the 2.0 version has made the following improvements:

Extract the Retrieved Data

Added Music information to the data category class MusicDao.

/*** Music information Data category class * Data Access Object */public class MusicDao {public List
 
  
GetMusicList () {List
  
   
Musics = new ArrayList <> (); if (Environment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED) {File musicDir = Environment. getExternalStoragePublicDirectory (Environment. DIRECTORY_MUSIC); if (musicDir. exists () {File [] files = musicDir. listFiles (); if (files! = Null & files. length> 0) {String title = ""; for (int I = 0; I
   
    

When loading data

MusicDao dao = new MusicDao();musics = dao.getMusicList();

Create different packages

Activity can be placed in Activity or UI package
DAL-> Data Access Layer
Entity-> Entity class

Adapter Improvement

Add BaseAdapter

Public abstract class BaseAdapter
     
      
Extends android. widget. BaseAdapter {private Context context; private List
      
       
Data; private LayoutInflater inflater; public BaseAdapter (Context context, List
       
        
Data) {this. context = context; this. data = data; inflater = LayoutInflater. from (this. context);}/*** get the LayoutInflate object * @ return */protected final LayoutInflater getLayoutInflater () {return inflater;} protected final List
        
         
GetData () {return data;} @ Override public int getCount () {return data. size () ;}@ Override public Object getItem (int I) {return null ;}@ Override public long getItemId (int I) {return 0 ;} @ Override public View getView (int I, View view, ViewGroup viewGroup) {return null ;}}
        
       
      
     

Modify MusicAdapter

public class MusicAdapter extends BaseAdapter
     
      {    public MusicAdapter(Context context, List
      
        data) {        super(context, data);    }    @Override    public View getView(int i, View view, ViewGroup viewGroup) {        Music music = getData().get(i);        if(view == null){            view = getLayoutInflater().inflate(R.layout.item_music,null);        }        TextView tvTitle = view.findViewById(R.id.tv_music_title);        TextView tvPath = view.findViewById(R.id.tv_music_path);        tvTitle.setText(music.getTitle());        tvPath.setText(music.getPath());        return super.getView(i, view, viewGroup);    }}
      
     

Related Article

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.