Android ImageView显示在CustomListView中的意外位置
我有一个自定义列表视图,显示图像图标和文本。我的取景器有问题。我只想显示仅在第一个位置(可能是0的位置)设置动画的ImageView,但是,ImageView会在自定义listview中的随机位置弹出,即使条件是position==0。 当我滚动listview时会发生这种情况。每当我向下滚动时,就会显示更多图像图标。我好几天都不能解决这个问题。我已经在下面设置了示例代码Android ImageView显示在CustomListView中的意外位置,android,listview,Android,Listview,我有一个自定义列表视图,显示图像图标和文本。我的取景器有问题。我只想显示仅在第一个位置(可能是0的位置)设置动画的ImageView,但是,ImageView会在自定义listview中的随机位置弹出,即使条件是position==0。 当我滚动listview时会发生这种情况。每当我向下滚动时,就会显示更多图像图标。我好几天都不能解决这个问题。我已经在下面设置了示例代码 public View getView(final int position, View convertView, View
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.customloto7newpack,
null);
holder = new ViewHolder();
// setting up the basic things in here
holder.left = (ImageView) convertView
.findViewById(R.id.newlotoicons);
holder.txt_maintext = (TextView) convertView // kumi
.findViewById(R.id.loto7newdesu);
holder.txt_lotodate = (TextView) convertView
.findViewById(R.id.datenew7);
// You can just add some new stuffs in here
// new addioitnal
holder.lotoname = (TextView) convertView
.findViewById(R.id.lotoname);
// holder.txt_mtext = (TextView) convertView
// .findViewById(R.id.txt_mtext);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (itemkey == 1) {
holder.lotoname.setText("itemname");
// setting up the 3 variables in here
holder.txt_maintext.setText(kai.get(position));
holder.txt_lotodate.setText("today" + loto_date.get(position));
if (position == 0) {
if (newIconParam.get(0).equals("OK")
|| newIconParam.get(0) == "OK") {
dateonly = loto_date.get(0).trim().toString();
dateonly2 = dateonly.replaceAll("\\(.*?\\) ?", "");
String date3 = dateonly2.trim();// use this to check
if (date3.equals(today)) {
logicflag = true;
holder.left.setBackgroundResource(R.drawable.blinker);
AnimationDrawable frameAnimation = (AnimationDrawable) holder.left
.getBackground();
frameAnimation.start();
} else if (!date3
.equals(today)) {
holder.left.setImageResource(R.drawable.new_icon);
// holder.left.setImageResource(android.R.color.transparent);
}
} else {
}
} else {
holder.left.setImageResource(android.R.color.transparent);
}
实际上有更多…我认为你应该停止其他视图上的动画。 尝试添加
((AnimationDrawable) holder.left).stop();
就在上面
holder.left.setImageResource(android.R.color.transparent);
在您的
else
声明中。谢谢,我将尝试一下。