Gives an error android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
<pre><code>public Spinner addSpinner(String spinnerTitle, int spinnerID,
            View view, ArrayAdapter&lt;String&gt; adapter, String defVal, boolean isOptional, Context context) {

        linflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        RelativeLayout spinner = (RelativeLayout) linflater.inflate(R.layout.custom_spinner, null);
        spinner.setVisibility(View.VISIBLE);
        TextView spinner_title = (TextView) spinner.findViewById(R.id.SpinnerTitle);
        spinner_title.setVisibility(View.VISIBLE);
        spinner_title.setText(spinnerTitle);
        spinner_title.setFocusable(false);
        spinner_title.setClickable(false);
        spinner_title.setWidth(EmsVariable.screenWidth);

        if(!isOptional){
            TextView asterix = (TextView) spinner.findViewById(R.id.Asterix);
            asterix.setVisibility(View.VISIBLE);
        }   

        Spinner sp = (Spinner) spinner.findViewById(R.id.Spinner01);
        sp.setAdapter(adapter);
        sp.setVisibility(View.VISIBLE);
        sp.setMinimumWidth(EmsVariable.screenWidth);
        sp.setId(spinnerID);
        int position = 1;
        if(defVal.length() &gt;0){
            position= adapter.getPosition(defVal);
        }
        sp.setSelection(position);
        ((RelativeLayout)view).addView(spinner);
        return sp;
    }
</code></pre>
