在ListView的每个项目中,都有一个ImageView。我已经使用AnimationDrawable设置了ImageDrawable。当ResultReceiver收到结果时,AnimationDrawable会启动或停止。
这是我的代码:
public class PicassoListNearbyAdapter extends BaseAdapter {
private PlaySoundServiceReceiver receiver;
@Override
public View getView ( final int position, View convertView, ViewGroup parent ) {
final ViewHolder viewHolder;
if ( convertView == null ) {
convertView = mInflater.inflate ( R.layout.nearby_fragment_info_listitem_layout, parent, false );
viewHolder = new ViewHolder ();
viewHolder.infoSound = ( ImageView ) convertView.findViewById ( R.id.infoSound );
convertView.setTag ( viewHolder );
} else {
viewHolder = ( ViewHolder ) convertView.getTag ();
}
viewHolder.infoSound.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick ( View v ) {
boolean isServiceRun = ServiceUtils.isServiceRun ( context, "com.***.service.PlaySoundService" );
if ( isServiceRun ) {
Intent intent = new Intent ( "android.intent.action.pauseRecordIntent" );
intent.putExtra ( "status", "pause" );
activity.sendBroadcast ( intent );
} else {
receiver.setListener ( new PlaySoundServiceReceiver.Listener () {
@Override
public void onReceiveResult ( int resultCode, Bundle resultData ) {
AnimationDrawable animationDrawable;
switch ( resultCode ) {
case 1024:
viewHolder.infoSound.setImageResource(R.drawable.animation1);
try {
viewHolder.infoSound.setImageDrawable ( activity.getResources ().getDrawable ( R.drawable.animation1 ) );
animationDrawable = ( AnimationDrawable ) viewHolder.infoSound.getDrawable ();
animationDrawable.start ();
} catch ( ClassCastException e ) {
e.printStackTrace ();
}
break;
case 1026:
viewHolder.infoSoundProgress.setVisibility ( View.GONE );
try {
animationDrawable = ( AnimationDrawable ) viewHolder.infoSound.getDrawable ();
animationDrawable.stop ();
} catch ( ClassCastException e ) {
e.printStackTrace ();
}
viewHolder.infoSound.setImageDrawable ( activity.getResources ().getDrawable ( R.drawable.yi_nearby_recordbutton ) );
boolean isServiceRun = ServiceUtils.isServiceRun ( context, "com.***.service.PlaySoundService" );
if ( isServiceRun ) {
activity.unbindService ( conn );
}
break;
}
}
} );
Intent intent = new Intent ( activity, PlaySoundService.class );
intent.setAction ( ACTION_PLAY );
intent.putExtra ( EXTRA_SOUND_URL, ( String ) list.get ( position ).get ( "commoditySound" ) );
intent.putExtra ( "rec", receiver );
activity.bindService ( intent, conn, Context.BIND_AUTO_CREATE );
}
}
} );
}
}
这是我的问题:
当一个AnimationDrawable启动时,其他列表项中的其他一些AnimationDrawable也会启动,但不是全部。
感谢您分享任何帮助/建议或经验。