use this
LinearLayout ll = (LinearLayout) findViewById(R.id.addSpinnerLayout);
LayoutInflater inflater = (LayoutInflater)selectedItemView.getContext().getSystemService(selectedItemView.getContext().LAYOUT_INFLATER_SERVICE)
View v = inflater.inflate(R.layout.addspinner_layout, null); // inflate addspinner
Spinner sp = (Spinner) v.findViewById(R.id.portfolioSpinner2); //portfolioSpinner2
ll.addView(v); // add the view to the linear layout
You have this
<LinearLayout
android:id="@+id/addSpinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
</LinearLayout>
I suppose you need to add the spinner to the linear layout.
So
LinearLayout ll = (LinearLayout) findViewById(R.id.addSpinnerLayout);
Inflate the layout
LayoutInflater inflater = (LayoutInflater)selectedItemView.getContext().getSystemService(selectedItemView.getContext().LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.addspinner_layout, null);
Then add it to LinearLayout
ll.addView(v); // add the view to the linear layout
To initialize Spinner
Spinner sp = (Spinner) v.findViewById(R.id.portfolioSpinner2);
coz you have this
<Spinner
android:id="@+id/portfolioSpinner2" // in addSpinner_layout