2
Ich habe eine benutzerdefinierte listview
, enthalten eine imageview
und eine textview
. Ich möchte, wenn ich imageview
in diesem starten, starten Sie animation(rotate)
. Mein Problem ist: Beim Scrollen wurde die Animation gestoppt.So starten Sie die Animation in benutzerdefinierten Listenansicht
public class AdapterFoodGroups extends BaseAdapter {
private static LayoutInflater mInflater = null;
Context context;
int[] foodImagesId;
String[] foodNameList;
String[] foodDescriptions;
int[] foodTimes;
boolean[] loadAnimation;
public AdapterFoodGroups(Context context, String[] foodNameList, String[] foodDescriptions, int[] foodTimes, int[] foodImagesId) {
// TODO Auto-generated constructor stub
this.foodNameList = foodNameList;
this.foodDescriptions = foodDescriptions;
this.foodTimes = foodTimes;
this.foodImagesId = foodImagesId;
this.context = context;
loadAnimation = new boolean[foodNameList.length];
for (boolean b: loadAnimation) {
b = false;
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder viewHolder;
final RotateAnimation anim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5 f, Animation.RELATIVE_TO_SELF, 0.5 f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(800);
if (convertView == null) {
mInflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.adapter_foodgroup, null);
viewHolder = new ViewHolder();
viewHolder.txtFoodName = (TextView) convertView.findViewById(R.id.txtFoodNameGrid);
viewHolder.txtFoodDescription = (TextView) convertView.findViewById(R.id.txtFoodDescriptionGrid);
viewHolder.txtFoodTime = (TextView) convertView.findViewById(R.id.txtFoodTimeGrid);
viewHolder.ivFoodImage = (CircularImageView) convertView.findViewById(R.id.ivFoodImageGrid);
viewHolder.ivLoad = (ImageView) convertView.findViewById(R.id.ivLoad);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (this.foodImagesId[position] != 0) {
viewHolder.ivFoodImage.setImageResource(this.foodImagesId[position]);
viewHolder.ivFoodImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, String.valueOf(position) + " = " + foodNameList[position], Toast.LENGTH_LONG).show();
}
});
}
if (this.foodNameList[position] != null) {
viewHolder.txtFoodName.setText(this.foodNameList[position]);
}
if (this.foodDescriptions[position] != null) {
viewHolder.txtFoodDescription.setText(this.foodDescriptions[position]);
}
if (this.foodTimes[position] != 0) {
viewHolder.txtFoodTime.setText(String.valueOf(this.foodTimes[position]) + " دقیقه");
}
viewHolder.ivLoad.setImageResource(R.drawable.load);
viewHolder.ivLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.ivLoad.setAnimation(anim);
viewHolder.ivLoad.startAnimation(anim);
}
});
return convertView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return foodNameList.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public static class ViewHolder {
public CircularImageView ivFoodImage;
public ImageView ivLoad;
public TextView txtFoodName;
public TextView txtFoodDescription;
public TextView txtFoodTime;
}
}
Hallo mein Freund. Ich mache das, aber nicht arbeiten. –
Ich habe Ihren Code versucht und wirklich gab es ein Problem. Ich habe meine Antwort bearbeitet und jetzt funktioniert es für meine. Versuchen Sie es und lassen Sie mich wissen, wenn es für Sie funktioniert –
sehr, sehr sehr danke ... sehr sehr sehr nützlich .... vielen Dank –