package com.exaple.music; import java.util.List; import java.util.Timer; import java.util.TimerTask; import com.exaple.vo.Music; import android.content.Context; import android.media.MediaPlayer; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageView; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; public class Base extends BaseAdapter { List<Music> list; Context co; private useMetod muse; private Timer timer; public Base(List<Music> list, Context co) { super(); this.list = list; this.co = co; /* singletonMusic = Singleton.SingletonMusic(); */ } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = null; final ViewHolder vh; if (convertView == null) { view = View.inflate(co, R.layout.base, null); vh = new ViewHolder(); vh.text = (TextView) view.findViewById(R.id.text); vh.start = (CheckBox) view.findViewById(R.id.start); vh.see = (SeekBar) view.findViewById(R.id.seek); vh.time1 = (TextView) view.findViewById(R.id.texttime1); vh.time2 = (TextView) view.findViewById(R.id.texttime2); view.setTag(vh); } else { view = convertView; vh = (ViewHolder) view.getTag(); } vh.text.setText(list.get(position).getName()); vh.start.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < list.size(); i++) { if (i != position) { list.get(i).setCheck(false); muse.onstop(); notifyDataSetChanged(); } } boolean check = list.get(position).isCheck(); if (check) { // 播放 muse.onplay(position); System.out.println(position); int long1 = Singleton.long1; System.out.println(long1 + "========="); vh.see.setMax(long1); muse.seek(vh.see, vh.time1, vh.time2); } else { muse.onstop(); MainActivity.cancelTime(); } } }); vh.start.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { list.get(position).setCheck(isChecked); } }); vh.start.setChecked(list.get(position).isCheck()); // 判断状态 if (list.get(position).isCheck()) { vh.see.setVisibility(View.VISIBLE); vh.time1.setVisibility(View.VISIBLE); vh.time2.setVisibility(View.VISIBLE); } else { vh.see.setVisibility(View.GONE); vh.time1.setVisibility(View.GONE); vh.time2.setVisibility(View.GONE); } vh.see.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (Singleton.play != null) { Singleton.play.seekTo(vh.see.getProgress()); muse.seek(vh.see, vh.time1, vh.time2); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { MainActivity.cancelTime(); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub } }); return view; } public class ViewHolder { TextView text; public CheckBox start; SeekBar see; TextView time1, time2; } public interface useMetod { void onplay(int position); void onstop(); void onCheck(CheckBox start); void seek(SeekBar seek, TextView text, TextView text1); } public void setIuse(useMetod usemetod) { muse = usemetod; } }