繁体   English   中英

在Android中使用闪烁的imageView时CustomListView中的错误

[英]Bugs in CustomListView when using blinking imageView in android

目前,我正在制作一个使用customlistview的简单应用,该应用显示“ new!”。 图标位于列表视图的第一个位置,并显示闪烁的“新!” 当前日期与json数据中的日期匹配时的图标。

显示正常的“新!”时 图标在第一个位置(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 

由于您使用的是视图保持器,因此视图再次返回屏幕时将再次使用。 因此,如果将视图设置为在第一位置可见,那么除非您明确将其设置为不可见,否则它将在其他位置可见。 答案将是这样的

AnimationDrawable frameAnimation = (AnimationDrawable) holder.left.getBackground();
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)) {

            //If the current date matches ,then show the blinking icon in the first position            
            logicflag = true;

            holder.left.setBackgroundResource(R.drawable.blinker);

            frameAnimation.start();
    }
    else if (!date3.equals(today) || date3 != today) {
        // want to show only the normal icon in the first position when the current date doesn't match
        holder.left.setImageResource(R.drawable.new_icon);
    }
}
else {
    //dont show icons in other parts of listview
    holder.left.setImageResource(android.R.color.transparent);
    frameAnimation.stop();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM