我有一个 ListView,我在其中动态地膨胀了 4 个不同的布局。在列表视图中的每个项目中,常见的东西是 3 个按钮。喜欢,不喜欢,评论。因此,当我们点击喜欢时,它会显示与喜欢相关的个人资料图片的图库。不喜欢和评论的方式相同。出现的问题是,当我点击喜欢时,它会显示正确的数据,但是当我向下滚动并且当该项目不在视野中时,当我向上滚动以查看该项目时,它会通过单击其他一些按钮来更改其视图。ListView中的每个Item都会发生这种情况需要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;
}