Dialog
のカスタム2つのタブをActivity
に表示しますが、次のエラーが表示されます。ダイアログ内のid ...のフラグメントが見つかりません
エラー:
No view found for id 0x7f0f0134 (com.hiro.chatio:id/viewPage_theme) for fragment
PostColorPickerFragment{35ffefce #0 id=0x7f0f0134 android:switcher:2131689780:0}
java.lang.IllegalArgumentException: No view found for id 0x7f0f0134 (com.hiro.chatio:id/viewPage_theme)
for fragment PostColorPickerFragment{35ffefce #0 id=0x7f0f0134 android:switcher:2131689780:0}
MainActivity
:
private Button pick_color;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_blog);
pick_color = (Button) findViewById(R.id.create_blog_color_btn);
pick_color.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(CreateBlogActivity.this);
dialog.setContentView(R.layout.blog_theme_picker);
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().getAttributes().windowAnimations = R.style.SlideUpDialogAnimation;
Button pickColor = (Button) dialog.findViewById(R.id.pick_color_btn);
Button default_color = (Button) dialog.findViewById(R.id.default_color);
TabLayout mTabLayout = (TabLayout) dialog.findViewById(R.id.main_tabs_theme);
CustomViewPager mViewPager = (CustomViewPager) dialog.findViewById(R.id.viewPage_theme);
ThemePagerAdapter mThemePagerAdapter = new ThemePagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mThemePagerAdapter);
mViewPager.setCurrentItem(0);
mViewPager.setPagingEnabled(false);
mTabLayout.setupWithViewPager(mViewPager); }); }
ThemePagerAdapter
:
public class ThemePagerAdapter extends FragmentPagerAdapter {
public ThemePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
PostColorPickerFragment postColorPickerFragment = new PostColorPickerFragment();
return postColorPickerFragment;
case 1:
PostThemePickerFragment postThemePickerFragment = new PostThemePickerFragment();
return postThemePickerFragment;
default:
return null;
}
}
@Override
public int getCount() {
return 2;
}
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Color";
case 1:
return "Theme";
default:
return null;
}
}
PostThemePickerFragment
:
public class PostThemePickerFragment extends Fragment {
public PostThemePickerFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.post_theme_picker, container, false);
return view;
}
どこ 'PostColorPickerFragment'コードは次のとおりです。?あなたは
onClick()
方法で持っていたすべてが今DialogFragment
で処理され、その方法は、単純になっていることがわかります–
'Dialog'の代わりに' DialogFragment'とその子 'FragmentManager'を使って' ViewPager'を動作させる必要があります。 'Activity'の' FragmentManager'は 'Activity'の階層には結びついていないので、' Dialog'で何も見つけられません。 –
マイクM.が正しいです。あなたは 'Dialog'の代わりに' DialogFragment'を使う必要があります。 – Wizard