Android Seekbar在自定义listview上运行

Android Seekbar在自定义listview上运行,android,listview,android-seekbar,Android,Listview,Android Seekbar,我正在开发一个音乐播放器,其中歌曲在我的列表行的列表视图中膨胀。我已经播放了暂停按钮和搜索栏。当我点击listview中第一首歌曲的播放按钮时,第一首歌曲将开始播放,但所有歌曲搜索栏将其位置更改为开始运行 我只想在单击时进行一次搜索 以下是我的适配器代码: public abstract class CustomAdapter extends BaseAdapter implements SeekBar.OnSeekBarChangeListener { Context contex

我正在开发一个音乐播放器,其中歌曲在我的列表行的列表视图中膨胀。我已经播放了暂停按钮和搜索栏。当我点击listview中第一首歌曲的播放按钮时,第一首歌曲将开始播放,但所有歌曲搜索栏将其位置更改为开始运行

我只想在单击时进行一次搜索

以下是我的适配器代码:

 public abstract class CustomAdapter extends BaseAdapter implements  SeekBar.OnSeekBarChangeListener {
    Context context;
    ArrayList<HashMap<String, String>> countryList;
    ArrayList<HashMap<String, String>> mStringFilterList;
    LayoutInflater inflter;
    public ImageView img2,img3;
    Handler mHandler = new Handler();
    SeekBar songProgressBar;

  public CustomAdapter(Context applicationContext, ArrayList<HashMap<String, String>> countryList) {
        this.context = applicationContext;
        this.countryList = countryList;
        mStringFilterList =  countryList;
        inflter = (LayoutInflater.from(applicationContext));
    }

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

    public void updateData(ArrayList<HashMap<String, String>> countryList) {
        this.countryList = countryList;
        notifyDataSetChanged();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

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

    @Override
    public View getView(final int position, View view, ViewGroup viewGroup) {
        view = inflter.inflate(R.layout.list_itemss, null);

        String hello = String.valueOf(countryList.get(position));
        String s = hello;
        int s1 = s.lastIndexOf("=");
        int s2 = s.lastIndexOf("}");

        String strSub = s.substring(s1+1,s2/*s.lastIndexOf("=")*/);
        Log.d("Hello",hello);       
        String henno1 = String.valueOf(hello.length());
        Log.d("hellya",henno1);
        songProgressBar = (SeekBar) view.findViewById(R.id.songProgressBar);

        TextView country = (TextView) view.findViewById(R.id.textView);
        country.setText(strSub);

        songProgressBar.setOnSeekBarChangeListener(this);

        songCurrentDurationLabel = (TextView)view.findViewById(R.id.songCurrentDurationLabel);

        songTotalDurationLabel = (TextView)view.findViewById(R.id.songTotalDurationLabel);

        img2 = (ImageView)view.findViewById(R.id.button3);
        img3 = (ImageView)view.findViewById(R.id.button2);
        img3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if(mp.isPlaying()){
                    if(mp!=null){
                        mp.pause();
                        Toast.makeText(Main.this,"Pause --",Toast.LENGTH_LONG).show();       
                   }
                }else{
                    Toast.makeText(Main.this,"Resume --",Toast.LENGTH_LONG).show();
                    // Resume song
                    if(mp!=null){
                       mp.start();                       
                  }
                }
            }
        });
        img2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img2.setVisibility(View.GONE);
                img3.setVisibility(View.VISIBLE);
                View parentRow = (View) view.getParent();
                Log.d("parentrow", String.valueOf(parentRow));
                //  Toast.makeText(Main.this,"Position is --"+position,Toast.LENGTH_LONG).show();
                int songIndex = position;

                currentSongIndex=songIndex;

                playSong(currentSongIndex);




                songProgressBar.setFocusable(true);
                songProgressBar.setEnabled(true);
                if (mp.isPlaying()) {
                    ((ImageView) view).setImageResource(R.drawable.pausebutton);

                }        
            }
        });


        ImageView img =(ImageView)view.findViewById(R.id.button);

        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(Main.this,"Added to Playlist",Toast.LENGTH_LONG).show();
                file = new File(path.get(position));
                listItems.add(String.valueOf(file));     
                customAdapter.notifyDataSetChanged();
            }
        });
        return view;
    }
    public void  playSong(int songIndex){
        // Play song
        Toast.makeText(Main.this,"Hellooo",Toast.LENGTH_LONG).show();
        try {
            mp.reset();
            mp.setDataSource(songsList.get(songIndex).get("songPath"));
            mp.prepare();
            mp.start();         

            img2.setImageResource(R.drawable.pausebutton);

            // set Progress bar values
            songProgressBar.setProgress(0);
            songProgressBar.setMax(100);

            // Updating progress bar
            updateProgressBar();

      } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void updateProgressBar() {
        mHandler.postDelayed(mUpdateTimeTask, 100);
    }
    public Runnable mUpdateTimeTask = new Runnable() {
        public void run() {
            long totalDuration = mp.getDuration();
            long currentDuration = mp.getCurrentPosition();

            // Displaying Total Duration time

            songTotalDurationLabel.setText(""+utils.milliSecondsToTimer(totalDuration));
            // Displaying time completed playing
            songCurrentDurationLabel.setText(""+utils.milliSecondsToTimer(currentDuration));

            // Updating progress bar
            int progress = (int)(utils.getProgressPercentage(currentDuration, totalDuration));
            //Log.d("Progress", ""+progress);
            songProgressBar.setProgress(progress);
            songProgressBar.setProgress(progress(.get(j));

            // Running this thread after 100 milliseconds
            mHandler.postDelayed(this, 100);
        }
    };
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    }    
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // remove message Handler from updating progress bar
        mHandler.removeCallbacks(mUpdateTimeTask);
    }
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        mHandler.removeCallbacks(mUpdateTimeTask);
        int totalDuration = mp.getDuration();
        int currentPosition = utils.progressToTimer(seekBar.getProgress(), totalDuration);

        // forward or backward to certain seconds
        mp.seekTo(currentPosition);

        // update timer progress again
        updateProgressBar();
    }
}
公共抽象类CustomAdapter扩展BaseAdapter实现SeekBar.OnSeekBarChangeListener{
语境;
ArrayList国家列表;
ArrayList mStringFilterList;
更平坦的过滤器;
公共图像视图img2、img3;
Handler mHandler=新的Handler();
SeekBar Songbar;
公共CustomAdapter(上下文应用程序上下文,ArrayList countryList){
this.context=applicationContext;
this.countryList=countryList;
mStringFilterList=国家列表;
inflter=(LayoutInflater.from(applicationContext));
}
@凌驾
public int getCount(){
返回countryList.size();
}
公共无效更新数据(ArrayList countryList){
this.countryList=countryList;
notifyDataSetChanged();
}
@凌驾
公共对象getItem(int i){
返回null;
}
@凌驾
公共长getItemId(int i){
返回0;
}
@凌驾
公共视图getView(最终整数位置、视图视图、视图组视图组){
视图=过滤器充气(R.layout.list\u items,空);
String hello=String.valueOf(countryList.get(position));
字符串s=hello;
int s1=s.lastIndexOf(“=”);
int s2=s.lastIndexOf(“}”);
字符串strSub=s.substring(s1+1,s2/*s.lastIndexOf(“=”*/);
Log.d(“你好”,你好);
String henno1=String.valueOf(hello.length());
日志d(“hellya”,henno1);
songProgressBar=(SeekBar)view.findViewById(R.id.songProgressBar);
TextView国家=(TextView)view.findViewById(R.id.TextView);
country.setText(strSub);
songProgressBar.setOnSeekBarChangeListener(此);
songCurrentDurationLabel=(TextView)view.findViewById(R.id.songCurrentDurationLabel);
songTotalDurationLabel=(TextView)view.findViewById(R.id.songTotalDurationLabel);
img2=(ImageView)view.findViewById(R.id.button3);
img3=(ImageView)view.findViewById(R.id.button2);
img3.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
if(mp.isPlaying()){
如果(mp!=null){
mp.pause();
Toast.makeText(Main.this,“Pause--”,Toast.LENGTH_LONG.show();
}
}否则{
Toast.makeText(Main.this,“Resume--”,Toast.LENGTH_LONG.show();
//简历歌
如果(mp!=null){
mp.start();
}
}
}
});
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
img2.setVisibility(View.GONE);
img3.设置可见性(视图.可见);
View parentRow=(View)View.getParent();
Log.d(“parentrow”,String.valueOf(parentrow));
//Toast.makeText(Main.this,“Position is--”+Position,Toast.LENGTH_LONG.show();
指数=位置;
currentSongIndex=songIndex;
播放歌曲(当前歌曲索引);
songProgressBar.setFocusable(真);
songProgressBar.setEnabled(true);
if(mp.isPlaying()){
((ImageView)视图).setImageResource(R.drawable.pausebutton);
}        
}
});
ImageView img=(ImageView)view.findViewById(R.id.button);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Toast.makeText(Main.this,“添加到播放列表”,Toast.LENGTH_LONG.show();
file=新文件(path.get(position));
add(String.valueOf(file));
customAdapter.notifyDataSetChanged();
}
});
返回视图;
}
公共void播放歌曲(int歌曲索引){
//播放歌曲
Toast.makeText(Main.this,“helloo”,Toast.LENGTH_LONG.show();
试一试{
mp.reset();
mp.setDataSource(songsList.get(songinindex.get)(“songPath”);
mp.prepare();
mp.start();
img2.setImageResource(R.drawable.pausebutton);
//设置进度条值
songProgressBar.setProgress(0);
songProgressBar.setMax(100);
//更新进度条
updateProgressBar();
}捕获(IllegalArgumentException e){
e、 printStackTrace();
}捕获(非法状态){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}
public void updateProgressBar(){
mHandler.postDelayed(mUpdateTimeTask,100);
}
public Runnable mUpdateTimeTask=new Runnable(){
公开募捐{
long totalDuration=mp.getDuration();
长currentDuration=mp.getCurrentPosition();
//显示总持续时间
songTotalDurationLabel.setText(“+utils.毫秒计时器(totalDuration));
//显示播放完成的时间
songCurrentDurationLabel.setText(“+utils.millisondstotimer(currentDuration));
//更新进度条
int progress=(int)(utils.getProgressPercentage(currentDuration,totalDuration));
//Log.d(“进度”,“进度+进度”);
songProgressBar.setProgress(进度)