Android ListView reports The specified child already has a paren

Source: Internet
Author: User

Today, I encountered a problem. I added The uploaded layout to listviev. When sliding up and down, The specified child already has a parent error is returned.

First paste the original code:

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {convertView = layoutInflater.inflate(R.layout.check_laizi_item_ll, null);RelativeLayout mRelativeLayout = (RelativeLayout) convertView.findViewById(R.id.clil_rl);List
 
   poker = mPokers.get(position);for (int j = 0; j < poker.size(); j++) {Poker card = poker.get(j);if (card.isLaiZi()) {card.getPokeImage().setImageDrawable(ImageUtil.getResDrawable(card.getBitpamResLaiZiID(), true));} else {card.getPokeImage().setImageDrawable(ImageUtil.getResDrawable(card.getBitpamResID(), true));}card.setId(position + 100);RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mst.adjustXIgnoreDensity(45), mst.adjustYIgnoreDensity(61));params.topMargin = mst.adjustYIgnoreDensity(card_jiange);params.leftMargin = mst.adjustXIgnoreDensity(card_jiange * j);card.getInnerLayout().setBackgroundDrawable(ImageUtil.getResDrawable(R.drawable.poker_div, true));card.getInnerLayout().setVisibility(View.GONE);card.setClickable(false);card.setLayoutParams(params);mRelativeLayout.addView(card);}return convertView;}
 


Paste the image again:



The reason is that my Poker control in listview is referenced by multiple convertviews.

Previously, I thought it was the reason why my convertView framework was reused. Therefore, I didn't take convertView. Every time I created a convertView, this error was also reported.

I think the problem should be in position. I am not difficult to explain the specific situation, but I feel that the changes in position and convertView are not synchronized in time. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + expires + crHy/vDx82ssr08L3A + expires = "brush: java;"> @ Overridepublic View getView (int position, View convertView, ViewGroup parent) {if (null = convertViews [position]) {convertView = layoutInflater. inflate (R. layout. check_laizi_item_ll, null); RelativeLayout mRelativeLayout = (RelativeLayout) convertView. findViewById (R. id. clil_rl); List Poker = mPokers. get (position); for (int j = 0; j <poker. size (); j ++) {Poker card = poker. get (j); if (card. isLaiZi () {card. getPokeImage (). setImageDrawable (ImageUtil. getResDrawable (card. getBitpamResLaiZiID (), true);} else {card. getPokeImage (). setImageDrawable (ImageUtil. getResDrawable (card. getBitpamResID (), true);} card. setId (position + 100); RelativeLayout. layoutParams params = new RelativeLayout. layoutParams (mst. adjustXIgnoreDensity (45), mst. adjustYIgnoreDensity (61); params. topMargin = mst. adjustYIgnoreDensity (card_jiange); params. leftMargin = mst. adjustXIgnoreDensity (card_jiange * j); card. getInnerLayout (). setBackgroundDrawable (ImageUtil. getResDrawable (R. drawable. poker_div, true); card. getInnerLayout (). setVisibility (View. GONE); card. setClickable (false); card. setLayoutParams (params); mRelativeLayout. addView (card); convertViews [position] = convertView;} else {convertView = convertViews [position];} Log. I ("positionss", "position:" + position + "mPokers. size: "+ mPokers. size () + "convertViews [position]:" + convertViews [position]); return convertView ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.