How to call the child's parent for this specified child that already has a
parent
This is the code:
public class HelpDetailsFragment extends Fragment
{
private static final String TAG = "MeMoGame";
public static HelpDetailsFragment newInstance(int index)
{
    HelpDetailsFragment detailFragment = new HelpDetailsFragment();
    Bundle bundleArgs = new Bundle();
    bundleArgs.putInt("index", index);
    detailFragment.setArguments(bundleArgs);
    return detailFragment;
}   // newInstance()
@Override
public View onCreateView(LayoutInflater inflater,
             ViewGroup container,
             Bundle savedInstanceState)
{
    if(container == null)
    {
    Log.i(TAG, "Different layouts and in one this fragment's containing
frame does not exist.");
        return null;
    } else {
        // I checked that container is NOT null
        Log.i(TAG, "This is the parent view that the fragment's UI should
be attached to.");
    }
    View mView = new View(getActivity());
    container.addView(mView);
    return container;
}
This error message appears: AndroidRuntime(785): Caused by:
java.lang.IllegalStateException: The specified child already has a parent.
You must call removeView() on the child's parent first.
Can / will someone please explain what I'm doing wrong?
When I do: View mView = new View(getActivity()); TextView text =
(TextView) new TextView() mView.addView(text); return mView; I get the
same error message.
 
No comments:
Post a Comment