2
我有一個ListView,其中我動態地膨脹4個不同的佈局。在列表視圖中的每個項目中,常見的事情是3個按鈕。喜歡,不喜歡,評論。所以當我們點擊它時,就會顯示與圖片相關的個人資料圖片。和厭惡和評論一樣。 問題出現了,當我點擊它會顯示正確的數據,但當我向下滾動,當該項目不在視圖中時,當我滾動查看該項目時,它會改變其視圖與其他一些按鈕單擊。 這發生在敵人的ListView 每一項都需要一個緊急援助getView的 代碼:Listview獲取重新創建並更改以前的視圖
@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;
}
我正在使用持有者...... – Vaibs
在這種情況下,如果您可以發佈代碼的適配器部分,它將更容易診斷 – darshanz