Android – view for fragment id not found in custom dialogfragment
•
Android
I knew there were many similar problems there, but I didn't find someone to solve my problem, so we left
In an activity, I have this Code:
TMTutorial tutorial = new TMTutorial();
tutorial.show(getSupportFragmentManager(), "blalba");
Tmtutorial looks like this:
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import tm.mello.se.R;
import tm.mello.se.TMWelcomeFragment;
public class TMTutorial extends DialogFragment{
View mRootView;
LayoutInflater mInflater;
public TMTutorial() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
mRootView = inflater.inflate(R.layout.tutorial_layout, container);
mInflater = inflater;
setupViewPager();
return mRootView;
}
private void setupViewPager()
{
ViewPager viewPager = (ViewPager) mRootView.findViewById(R.id.tutorial_pager);
viewPager.setAdapter(new Test(getFragmentManager()));
//viewPager.setAdapter(new Test(getFragmentManager()));
}
public class Test extends FragmentPagerAdapter
{
public Test(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int i)
{
return new TMWelcomeFragment();
}
@Override
public int getCount()
{
return 3;
}
}
}
tutorial_ Layout.xml is like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tutorial_pager"/>
</FrameLayout>
I get this stack trace:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: No view found for id 0x7f05009d (xx.xxxx.xx:id/tutorial_pager) for fragment TMWelcomeFragment{42050698 #1 id=0x7f05009d android:switcher:2131034269:0}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:16030)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
at android.view.View.measure(View.java:16030)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
at android.view.View.measure(View.java:16030)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
at android.view.View.measure(View.java:16030)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
at android.view.View.measure(View.java:16030)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16030)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:314)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2196)
at android.view.View.measure(View.java:16030)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1913)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1083)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1288)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5505)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Who knows what the problem is S
resolvent:
You need to use
viewPager.setAdapter(new Test(getChildFragmentManager()))
replace
getSupportFragmentManager()
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码