当我填充我的SimpleAdapter
. 在getView()
我检查视频是否已经存在的方法上。如果它已经存在,我会将按钮的图像更改为“播放”图像。否则,我将保留其“下载”图像。问题是当我滚动列表时,它会将所有按钮更改为“播放”图像。这是我的代码,我做错了什么?
public View getView(int position, View convertView, ViewGroup parent) {
View row=super.getView(position, convertView, parent);
TextView videoIdText = (TextView) row.findViewById(R.id.videoId);
Button downloadButton = (Button) row.findViewById(R.id.videoDownload);
final String videoId = videoIdText.getText().toString();
if (videoExists(videoId)) {
downloadButton.setBackgroundResource( R.drawable.ic_play );
Drawable d = downloadButton.getBackground();
d.setColorFilter(Color.parseColor("#00AA00"),Mode.SRC_ATOP);
downloadButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View view) {
if (activity !=null){
((FeedActivity)activity).playVideo(getVideoPath(videoId));
}
}
});
}else{
downloadButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View view) {
DownloadTask task = new DownloadTask();
task.setVideoId(videoId);
task.execute();
}
});
}