【发布时间】:2015-06-05 02:43:22
【问题描述】:
目前,我正在制作一个使用 customlistview 的简单应用程序,该应用程序显示“新!”图标在 listView 的第一个位置,并显示一个闪烁的“new!!”当前日期与 json 数据中的日期匹配时的图标。
当显示正常的“new!”时图标在第一个位置 (0),一切都很好,因为它只显示在第一个位置。但是,当使用闪烁的图标时,它会在向下滚动时显示在列表视图的随机位置。
由于没有错误,我发现这个问题很难解决。
我提供了我自己的示例代码'在下面使用。
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.newicons);
holder.txt_maintext = (TextView) convertView
.findViewById(R.id.loto7newdesu);
holder.txt_lotodate = (TextView) convertView
.findViewById(R.id.datenew7);
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 (key == 1) {
holder.lotoname.setText("key1");
// setting up the 3 variables in here
holder.txt_maintext.setText(kai.get(position));
holder.txt_lotodate.setText("New Date:" + 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);
}
} else if (key2 == 2) {
holder.lotoname.setText("Key2");
holder.txt_maintext.setText(kai.get(position));
holder.txt_lotodate.setText("New Date: " + 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();
if (date3.equals(today)) {
// if (loto_date.get(0).trim().toString().equals(today))
// {
logicflag = true;
/*
* holder.left.setBackgroundResource(R.drawable.blinker);
* AnimationDrawable frameAnimation =
* (AnimationDrawable) holder.left.getBackground();
* frameAnimation.start();
*
*
*/
} else if (!date3.equals(today) || date3 != today) {
holder.left.setImageResource(R.drawable.new_icon);
}
}
} else {
holder.left.setImageResource(android.R.color.transparent);
}
} else if (key3 == 3) {
//similar
【问题讨论】:
标签: java android android-listview custom-lists