Repository: rey5137/material

Issue #219: Spinner java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Created: 2015-08-16T14:10:29Z
I'm trying to use com.rey.material.widget.Spinner in a fragment but I'm getting the following error when I try to change spinner value. Could you please help me with the issue. Thank you for your time.
Here is the code and error
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.rey.material.widget.Spinner;
public class SpinnerFragment extends Fragment {
View SpinV;

String items[] = {"Choose type of vehicle","Car","Bus","Two wheeler","Lorry","Other"};
Spinner spn_label;

public SpinnerFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    if(SpinV==null) {
        SpinV = inflater.inflate(R.layout.fragment_spinns, container, false);
    }
    spn_label = (Spinner)SpinV.findViewById(R.id.spinner_label);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.row_spn, items);
    adapter.setDropDownViewResource(R.layout.row_spn_dropdown);
    spn_label.setAdapter(adapter);

    return SpinV;
}

}
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3881)
at android.view.ViewGroup.addView(ViewGroup.java:3734)
at android.view.ViewGroup.addView(ViewGroup.java:3679)
at android.view.ViewGroup.addView(ViewGroup.java:3655)
at com.rey.material.widget.Spinner.onDataInvalidated(Spinner.java:927)
at com.rey.material.widget.Spinner.setSelection(Spinner.java:422)
at com.rey.material.widget.Spinner.performItemClick(Spinner.java:898)
at com.rey.material.widget.Spinner$DropdownPopup$3.onItemClick(Spinner.java:1271)
at com.rey.material.widget.Spinner$DropDownAdapter.onClick(Spinner.java:1140)
at com.rey.material.widget.RippleManager.run(RippleManager.java:100)
at com.rey.material.widget.RippleManager.onClick(RippleManager.java:93)
at android.view.View.performClick(View.java:4759)
at android.view.View$PerformClick.run(View.java:19770)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

Duplicate issue #267: Crash app when i use Snipper after clicking an item
Created: 2015-09-29T08:08:28Z
我给Snipper绑定简单的arrayadpter用于测试，居然在点选一项后当掉。从错误代码上看到点击处理，且错误出现在其后（Spinner.onDataInvalidated）一个addview行为，这是干什么的呢？我不明白。
for testing , I bind the spinner with a simple adapter, but crash after selecting an item. From error output ,we can find the select / click event handle, and a strange Spinner.onDataInvalidated follow, in that a serial addView behavior , What that for??
09-29 15:39:34.836  17378-17378/cn.wildlife.sugeladi E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3491)
at android.view.ViewGroup.addView(ViewGroup.java:3362)
at android.view.ViewGroup.addView(ViewGroup.java:3307)
at android.view.ViewGroup.addView(ViewGroup.java:3283)
at com.rey.material.widget.Spinner.onDataInvalidated(Spinner.java:927)
at com.rey.material.widget.Spinner.setSelection(Spinner.java:422)
at com.rey.material.widget.Spinner.performItemClick(Spinner.java:898)
at com.rey.material.widget.Spinner$DropdownPopup$3.onItemClick(Spinner.java:1271)
at com.rey.material.widget.Spinner$DropDownAdapter.onClick(Spinner.java:1140)
at android.view.View.performClick(View.java:4171)
at android.view.View$PerformClick.run(View.java:17097)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
at dalvik.system.NativeStart.main(Native Method)

Closing comment (2015-10-01T20:11:33Z): Duplicate of #219