I have an activity in which there is a piece. There is a button inside that piece, which should be clicked when the piece of pieces (pieces, too) will be replaced by a piece inside.
However, when the tab piece is full and I try to find my viewer by ID, FindViewById () returns empty.
Here is my code: inside the piece with the button:
@Override Public Zero (click view) {switch (view.getId ()) { Case R.id.gewichtActualiserenButton: // TODO Apply Tab // GewichtTabsFragment MainActivity replace the current section with mainActivity = (main activity) getActivity (); GewichtTabsFragment gewichtTabsFragment = New GewichtTabsFragment (); Main activity. Substantiation (gewichtTabsFragment, Constants.GEWICHT_TABS_FRAGMENT); break; Case R.id.geburtsdatumEditText: showDatePickerDialog (see); break; Case R.id.hundImageView: // Display the warning to choose from the camera or gallery ImageSourceChooserDialog newFragment = New ImageSourceChooserDialog (); NewFragment.setHundFragment (this); NewFragment.setWithDeleteItem (true); ImgChooserDialog = newFragment; Newfragment.show (getActivity (). GetSupportFragmentManager (), "image_source_chooser"); break; Case R.id.zusaetzeSwitch: // toggle active status zusaetze edit text GetZusaetzeEditText (). SetEnabled (! GetZusaetzeEditText (). IsEnabled ()); Default: Break; }
GewichtTabsFragment.java:
@ Override public view creatives (LayoutEfterter Inflator, View Group Container, Bundle Saved InstantState) {// For this Increase the layout view section see = inflater.inflate (R. fragment_gigThat_tab, container, incorrect); Main activity main activity = (main activity) getActivity (); // Get ViewPager and set it to a pager adapter so that it can display items / / tap the following call returns? Why? ViewPager viewPager = (ViewPager) view.findViewById (R.id.viewpager); ViewPager.setAdapter (new GewichtFragmentPagerAdapter (mainActivity.getSupportFragmentManager ())); // Pager SlidingTabriptition ViewPager Pagerlide Tabstrip Tab Strip = (Pagerlide Tabstrip) getActivity () FindViewById (R.id.tabs); // View Tab Bar Tabs Attach PageRank Strip.setViewPager (viewPager); Return view; }
and the layout file fragment_gewicht_tabs.xml:
"True" Android: layout_width = "match_perrent" android: layout_height = "48dp" & gt; & Lt; /com.astuetz.PagerSlidingTabStrip> Android: Android: Android: Android: Android: Android: Android: Android: "Android: Color / White" /> ; & Lt; / LinearLayout & gt;
Why is ViewById returns empty?
This will be zero because you are trying to get the view that has not been created yet. has gone. Change then
ViewPager viewPager = (ViewPager) view.findViewById (R.id.viewpager);
From
View pager viewpages = (Viewpoint) getActivity (). FindViewById (RID Overview);
No comments:
Post a Comment