[General Questions and Answers] sachi@dev15:
Please find my implementation of getView() in my adapter class which extends BaseAdapter().

public View getView(int position, View convertView, ViewGroup parent) {

View vi = convertView;

ViewHolder holder = null;

tempValues=null;

if(position <ArrayListObj.size()){

tempValues = (ObjectCLASS) ArrayListObj.get(position);

if (convertView == null) {

holder = new ViewHolder();

holder.position = position;

if(tempValues.getType()==EventListItem.Cond1 || tempValues.getType()==EventListItem.Cond2){

if(tempValues.getType()==EventListItem.Cond1)

vi = inflater.inflate(R.layoutM1, null);

else if(tempValues.getType()==EventListItem.Cond2)

vi = inflater.inflate(R.layoutM2, null);

//dynamic content is getting added here

middleContentTopRapperView = new LinearLayout(mContext);

middleContentTopRapperView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

middleContentTopRapperView.setOrientation(LinearLayout.VERTICAL);

//static content from xml layout added here

holder.t1 = (TextView) vi.findViewById(R.id.t1);

holder.m1 = (TextView) vi.findViewById(R.id.m1);

holder.rightView = (View) vi.findViewById(R.id.rightView);//one of(right child view) child of parentRowItemRelativeLayout

holder.r1 = (TextView) vi.findViewById(R.id.r1);

holder.lh1 = (TextView) vi.findViewById(R.id.lh1);

holder.im1 = (ImageView) vi.findViewById(R.id.im1);

holder.li1 = (LinearLayout) vi.findViewById(R.id.li1);

// extracting the parent layouts from the xml to add the last child dynamically

holder.parentRowItemRelativeLayout = (RelativeLayout) vi.findViewById(R.id.parentRowItemRelativeLayout);// row item parent

holder.topRootLayout = (LinearLayout) vi.findViewById(R.id.topRootLayout); // root of the xml

holder.leftView = (RelativeLayout) vi.findViewById(R.id.leftView);// one of(left child view) child of parentRowItemRelativeLayout

holder.count=position;

} else if (tempValues.getType() == CondN2) {

vi = inflater.inflate(R.layout0, null);

holder.viewS1 = (TextView)vi.findViewById(R.id.S1);

} else if (tempValues.getType() == CondN3) {

vi = inflater.inflate(R.layout1, null);

// do get some view of layout1

// do some localization stuff here

//do some x1 stuff here

//do some x stuff here

} else if (tempValues.getType() == condN1) {

vi = inflater.inflate(R.layout2, null);

}

vi.setTag(holder);

} else {

holder = (ViewHolder) vi.getTag();

}

if(tempValues.getType()==Cond1 || tempValues.getType()==Cond2)

{

if (!holder.isYesAdded && tempValues.getValue().getValueType() == "Cond3")

{

addRow("String1", "String2", position,false,holder.topRootLayout,holder.parentRowItemRelativeLayout,holder.leftView,holder.rightView,tempValues.getType());

// above function does this --> middleContentTopRapperView.addView(row);

// where is row is a object of a class which extends LinearLayout and adds some component like text-view .

holder.parentRowItemRelativeLayout.addView(middleContentTopRapperView);

holder.isYesAdded = true;

}

}

}

return vi;

}

I got this Exception when i am trying to add more than 1 list items dynamically to holder.parentRowItemRelativeLayout.

Got the exception here on this line : holder.parentRowItemRelativeLayout.addView(middleContentTopRapperView);

Btw, the way this block will get added dynamically based on the condition, so if that condition fails it will not add, but if one item added based on the condition then if i scroll up or down 4/5 times it will give the same exception.

Say 5 items are there in listview and out of that 1 item is based on the above mentioned condition.

ava.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.addViewInner(ViewGroup.java:4187)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.addView(ViewGroup.java:4040)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.addView(ViewGroup.java:3985)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.addView(ViewGroup.java:3961)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at com.bayer.onyx.MyBaseAdapter.getView(MyBaseAdapter.java:538)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.AbsListView.obtainView(AbsListView.java:2842)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.ListView.makeAndAddView(ListView.java:1884)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.ListView.fillDown(ListView.java:713)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.ListView.fillGap(ListView.java:677)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.AbsListView.trackMotionScroll(AbsListView.java:7030)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:4179)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.AbsListView.onTouchMove(AbsListView.java:5541)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.AbsListView.onTouchEvent(AbsListView.java:5376)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.View.dispatchTouchEvent(View.java:8920)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2673)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2385)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.widget.AbsListView.dispatchTouchEvent(AbsListView.java:5318)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at com.bayer.onyx.MyListView.dispatchTouchEvent(MyListView.java:283)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2552)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1767)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.app.Activity.dispatchTouchEvent(Activity.java:2840)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2513)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.View.dispatchPointerEvent(View.java:9125)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4632)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4470)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4153)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4210)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)

09-24 00:49:22.187: E/AndroidRuntime(15204):	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6480)