列表视图得到重建,并改变了previous意见 [英] Listview gets recreated and changes the previous views

查看:146
本文介绍了列表视图得到重建,并改变了previous意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我动态充气4种不同的布局一个ListView。在列表视图中的每一项共同的东西是3个按键。喜欢,不喜欢,评论。所以,当我们点击喜欢它显示与相关个人资料图片画廊。而同样的方式为不喜欢和注释。
问题出现,当我点击喜欢它会显示正确的数据,但是当我向下滚动,当项目超出视图然后当我回滚动到查看该项目改变其与其他一些按钮,点击查看。
这发生在敌我的ListView每个项目
需要紧急帮助
getView的code:

  @覆盖
    公共查看getView(INT位置,查看convertView,父母的ViewGroup){
        // TODO自动生成方法存根
        mInflater = LayoutInflater.from(mContext);
            POS =位置;
        如果(convertView == NULL){
            Log.e(-------- ---------内,convertView ==空);
            持有人=新的持有人();
            convertView = mInflater.inflate(R.layout.custom_stream_list,NULL);
            holder.childView =(的LinearLayout)convertView.findViewById(R.id.view_to_inflate);
            holder.myGallery =(图库论坛)convertView.findViewById(R.id.myGallery_stream);
            holder.like =(ImageView的)convertView.findViewById(R.id.like_stream);
            holder.dislike =(ImageView的)convertView.findViewById(R.id.dislike_stream);
            holder.comment =(ImageView的)convertView.findViewById(R.id.comment_stream);
            holder.commentLayout =(RelativeLayout的)convertView.findViewById(R.id.comment_view_to_inflate);
            holder.comment_name =(TextView中)convertView.findViewById(R.id.comment_name);
            holder.comment_description =(TextView中)convertView.findViewById(R.id.comment_description);
            holder.comment_time =(TextView中)convertView.findViewById(R.id.comment_time);            convertView.setTag(保持器);
        }其他{
            Log.e(-------- ---------内,else语句);
            支架=(座)convertView.getTag();
        }
        holder.myGallery.setVisibility(View.INVISIBLE);        holder.like.setTag(保持器);
        holder.dislike.setTag(保持器);
        holder.comment.setTag(保持器);        holder.myGallery.setSpacing(5);
        holder.like.setOnClickListener(本);
        holder.dislike.setOnClickListener(本);
        holder.comment.setOnClickListener(本);
        如果((位置%4)== 0){
            Log.e(--------内部---------,位置== 0);
            followLayoutView = mInflater.inflate(R.layout.abc,NULL);
            holder.news_titile =(TextView中)followLayoutView.findViewById(R.id.news_article_titile);
            holder.news_description =(TextView中)followLayoutView.findViewById(R.id.news_article_description);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView);        }如果((位置%4)== 1){
            Log.e(--------内部---------,位置== 1);
            followLayoutView1 = mInflater.inflate(R.layout.xyz,NULL);
            holder.match_event_title =(TextView中)followLayoutView1.findViewById(R.id.match_events_stream_titile);
            holder.match_event_time =(TextView中)followLayoutView1.findViewById(R.id.following_time);
            holder.match_event_description =(TextView中)followLayoutView1.findViewById(R.id.match_events_stream_description);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView1);
        }如果((位置%4)== 2){
            Log.e(--------内部---------,位置== 2);
            followLayoutView2 = mInflater.inflate(R.layout.pqr,NULL);
            holder.match_event_title =(TextView中)followLayoutView2.findViewById(R.id.match_events_stream_titile);
            holder.match_event_time =(TextView中)followLayoutView2.findViewById(R.id.following_time);
            holder.match_event_description =(TextView中)followLayoutView2.findViewById(R.id.match_events_stream_description);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView2);        }如果((位置%4)== 3){
            Log.e(--------内部---------,位置== 3);
            followLayoutView3 = mInflater.inflate(R.layout.mno,NULL);
            holder.video_background =(ImageView的)followLayoutView3.findViewById(R.id.video_background);
            holder.play =(ImageView的)followLayoutView3.findViewById(R.id.video_play);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView3);
        }        返回convertView;
    }


解决方案

我猜你没有使用持有人的动态列表。
使用以持有人模式来避免这个问题。
希望这有助于链接。
http://www.vogella.com/articles/AndroidListView/article.html

I have a ListView in which I inflate 4 different layouts dynamically. In every Item in listview the common things are 3 buttons. Like ,dislike, comment. So when we click on like it shows up with gallery with profile pictures related to like. And same way for dislike and comment. The problem arises that when I click on like it will show up proper data but when I scroll down and when that Item is out of view then when i scroll back up to view that Item it changes its view with some other button click. This happens foe every Item in ListView Need a urgent help Code of getView:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        mInflater= LayoutInflater.from(mContext);
            pos=position;
        if(convertView==null){
            Log.e("--------Inside---------", "convertView==null");
            holder= new Holder();
            convertView = mInflater.inflate(R.layout.custom_stream_list, null);
            holder.childView= (LinearLayout) convertView.findViewById(R.id.view_to_inflate);
            holder.myGallery= (Gallery) convertView.findViewById(R.id.myGallery_stream);
            holder.like= (ImageView) convertView.findViewById(R.id.like_stream);
            holder.dislike =(ImageView) convertView.findViewById(R.id.dislike_stream);
            holder.comment = (ImageView) convertView.findViewById(R.id.comment_stream);
            holder.commentLayout = (RelativeLayout) convertView.findViewById(R.id.comment_view_to_inflate);
            holder.comment_name = (TextView) convertView.findViewById(R.id.comment_name);
            holder.comment_description = (TextView) convertView.findViewById(R.id.comment_description);
            holder.comment_time = (TextView) convertView.findViewById(R.id.comment_time);

            convertView.setTag(holder);
        }else {
            Log.e("--------Inside---------", "else Statement");
            holder= (Holder) convertView.getTag();
        }
        holder.myGallery.setVisibility(View.INVISIBLE);

        holder.like.setTag(holder);
        holder.dislike.setTag(holder);
        holder.comment.setTag(holder);



        holder.myGallery.setSpacing(5);


        holder.like.setOnClickListener(this);
        holder.dislike.setOnClickListener(this);
        holder.comment.setOnClickListener(this);


        if((position%4)==0){
            Log.e("--------Inside---------", "position==0");
            followLayoutView = mInflater.inflate(R.layout.abc, null);
            holder.news_titile=(TextView) followLayoutView.findViewById(R.id.news_article_titile);
            holder.news_description= (TextView) followLayoutView.findViewById(R.id.news_article_description);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView);

        } if((position%4)==1){
            Log.e("--------Inside---------", "position==1");
            followLayoutView1 = mInflater.inflate(R.layout.xyz, null);
            holder.match_event_title= (TextView) followLayoutView1.findViewById(R.id.match_events_stream_titile);
            holder.match_event_time= (TextView) followLayoutView1.findViewById(R.id.following_time);
            holder.match_event_description= (TextView) followLayoutView1.findViewById(R.id.match_events_stream_description);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView1);


        } if((position%4)== 2){
            Log.e("--------Inside---------", "position==2");
            followLayoutView2 = mInflater.inflate(R.layout.pqr, null);
            holder.match_event_title= (TextView) followLayoutView2.findViewById(R.id.match_events_stream_titile);
            holder.match_event_time= (TextView) followLayoutView2.findViewById(R.id.following_time);
            holder.match_event_description= (TextView) followLayoutView2.findViewById(R.id.match_events_stream_description);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView2);

        } if((position%4)==3){
            Log.e("--------Inside---------", "position==3");
            followLayoutView3 = mInflater.inflate(R.layout.mno, null);
            holder.video_background= (ImageView) followLayoutView3.findViewById(R.id.video_background);
            holder.play = (ImageView) followLayoutView3.findViewById(R.id.video_play);
            holder.childView.removeAllViews();
            holder.childView.addView(followLayoutView3);


        }

        return convertView;
    }

解决方案

I guess you are not using Holder for your dynamic list. Use Holder Pattern in order to avoid that issue. Hope this link helps. http://www.vogella.com/articles/AndroidListView/article.html

这篇关于列表视图得到重建,并改变了previous意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆