Android Open Source - NPlayer Music Adapter






From Project

Back to project page NPlayer.

License

The source code is released under:

Apache License

If you think the Android project NPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.qinxiandiqi.adapter;
//from www  . j a va  2 s  .  c  om
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qinxiandiqi.nplayer.R;
import com.qinxiandiqi.utils.AdapterUtils;
import com.qinxiandiqi.utils.CodeUtils;

public class MusicAdapter extends BaseAdapter {

  private LayoutInflater inflater;
  private int defaultimage;

  public MusicAdapter(Context context, int defaultimage) {
    this.inflater = LayoutInflater.from(context);
    this.defaultimage = defaultimage;
  }

  @Override
  public int getCount() {
    return CodeUtils.musicFileList.size();
  }

  @Override
  public Object getItem(int position) {
    return CodeUtils.musicFileList.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    Holder holder;
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.mediaitem, null);
      holder = new Holder();
      holder.imageView = (ImageView) convertView
          .findViewById(R.id.mediaitemimage);
      holder.textView = (TextView) convertView
          .findViewById(R.id.mediaitemtext);
      convertView.setTag(holder);
    } else {
      holder = (Holder) convertView.getTag();
    }

    if(position == CodeUtils.playingMusic){
      convertView.setBackgroundResource(R.color.clickitem);
    }else{
      convertView.setBackgroundResource(R.color.listitem);
    }
    
    holder.imageView = AdapterUtils.setImageView(position,
        CodeUtils.playingMusic, CodeUtils.playingMusicState,
        holder.imageView, defaultimage);

    holder.textView.setText((position + 1) + "."
        + CodeUtils.musicFileList.get(position).getMediaName());
    
    return convertView;
  }

  static class Holder {
    public ImageView imageView;
    public TextView textView;
  }
}




Java Source Code List

com.qinxiandiqi.adapter.MusicAdapter.java
com.qinxiandiqi.adapter.VideoAdapter.java
com.qinxiandiqi.bean.MediaFile.java
com.qinxiandiqi.bean.MusicFile.java
com.qinxiandiqi.bean.VideoFile.java
com.qinxiandiqi.nplayer.MainActivity.java
com.qinxiandiqi.nplayer.MusicActivity.java
com.qinxiandiqi.nplayer.SearchActivity.java
com.qinxiandiqi.nplayer.VideoActivity.java
com.qinxiandiqi.service.MusicService.java
com.qinxiandiqi.utils.AdapterUtils.java
com.qinxiandiqi.utils.CodeUtils.java
com.qinxiandiqi.utils.FileUtils.java
com.qinxiandiqi.utils.MediaUtils.java
com.qinxiandiqi.utils.PlayingUtils.java
com.qinxiandiqi.utils.PreferenceUtils.java
com.qinxiandiqi.utils.XMLUtils.java