getview()没有调用按钮点击?

时间:2014-02-06 10:30:30

标签: java android listview audio-player android-music-player

我正在开发一个音乐播放器。所有歌曲都放在ListViewImageButton。此按钮正在播放和暂停歌曲。所以我使用的是getview()。但是当我点击ImageButton时,歌曲正在播放和暂停,但播放/暂停的图像不会改变。我认为我的主要问题是,当我点击ImageButton时,它没有调用getview()。所以请帮助我。

 @Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_ringtones);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ringtones);
    mAdapter = new RingtonesMusicAdapter(this, R.layout.ringtones_row);
    mListView.setAdapter(mAdapter);
 }

 public void invalidatePlayButtons(int position) {
    for (int i = 0; i < mTrackData.size(); i++) {
        if (i != position) {
            try {
                //mTrackData.get(i).getRowItem().mPlayButton.setImageResource(R.drawable.play);
                if (MusicManager.getInstance().isPlaying(mTrackData.get(i))) {
                    MusicManager.getInstance().stop();
                    mTrackData.get(i).getRowItem().mProgressBar
                            .setProgress(0);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else
            mTrackData.get(i).getRowItem().mPlayButton
                    .setImageResource(R.drawable.pause);
    }
}

 public void onPlayClick(View view) {
    Object obj = view.getTag();

    if (obj != null && obj.getClass() == RowItem.class) {
        final RowItem rowItem = (RowItem) obj;
        if(rowItem.mPosition != mChantIndex ){
            if (!MusicManager.getInstance().isPlaying(rowItem)) {
                invalidatePlayButtons(rowItem.mPosition);
                MusicManager.getInstance().showProgressAnimation(rowItem.mProgressBar);
            //  rowItem.mPlayButton.setImageResource(R.drawable.pause);
                if(rowItem.isPause){
                    //rowItem.mPlayButton.setImageResource(R.drawable.pause);
                    MusicManager.getInstance().setLengthTrack();
                }else{
                    rowItem.mMusicListener = this;
                    MusicManager.getInstance().playDownloadedTrack(rowItem);
                     if(rowItem.mPosition == mProgressbarIndex) {
                            mProgressbarIndex = -1;  
                        }
                        else {
                            mProgressbarIndex = rowItem.mPosition;
                        } 
                }
            }else if(MusicManager.getInstance().isPlaying(rowItem)){
                MusicManager.getInstance().pauseTrack(rowItem);
                MusicManager.getInstance().getLengthTrack();
                //rowItem.mPlayButton.setImageResource(R.drawable.play);
                rowItem.isPause = true;
            }
        }
    }else {
        invalidatePlayButtons(-1);
    }
    //mAdapter.notifyDataSetChanged();
}
@Override
public void onRefreshData(Refreshable refreshable, int requestCode) {
    if (requestCode == SoundCloudManager.BITMAP_DATA) {
        mAdapter.notifyDataSetChanged();
    }


class RingtonesMusicAdapter extends ArrayAdapter<LinearLayout>{

    Context mContext;
    int mResource;

    public RingtonesMusicAdapter(Context context, int resource) {
        super(context, resource);
        mContext =context;
        mResource = resource;
    }

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

    public LinearLayout getItem(int position) {
        return null;
        }

    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout row;
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        row =(LinearLayout)inflater.inflate(mResource, parent, false);

        RowItem rowItem = new RowItem(position);
        mTrackData.get(position).setRowItem(rowItem);
        rowItem.mTrack = mTrackData.get(position);
        rowItem.setupRowForRingtone(row);
        return row;
    }

    @Override
    public boolean isEnabled(int position) {
        return true;
    }
}

方法rowItem.setupRowForRingtone(row)具有更改播放/暂停图像的代码。

0 个答案:

没有答案