下面列出了android.app.Fragment#getView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Scrollable getCurrentScrollable() {
Fragment fragment = getCurrentFragment();
if (fragment == null) {
return null;
}
View view = fragment.getView();
if (view == null) {
return null;
}
switch (mViewPager.getCurrentItem()) {
case 0:
return (Scrollable) view.findViewById(R.id.tvdetailsinfo);
case 1:
return (Scrollable) view.findViewById(R.id.castList);
case 2:
return (Scrollable) view.findViewById(R.id.tvdetailsoverview);
default:
return (Scrollable) view.findViewById(R.id.tvdetailsinfo);
}
}
private Scrollable getCurrentScrollable() {
Fragment fragment = getCurrentFragment();
if (fragment == null) {
return null;
}
View view = fragment.getView();
if (view == null) {
return null;
}
switch (mViewPager.getCurrentItem()) {
case 0:
return (Scrollable) view.findViewById(R.id.movieslist);
case 1:
return (Scrollable) view.findViewById(R.id.nowplaying);
case 2:
return (Scrollable) view.findViewById(R.id.popular);
case 3:
return (Scrollable) view.findViewById(R.id.toprated);
default:
return (Scrollable) view.findViewById(R.id.movieslist);
}
}
private Scrollable getCurrentScrollable() {
Fragment fragment = getCurrentFragment();
if (fragment == null) {
return null;
}
View view = fragment.getView();
if (view == null) {
return null;
}
switch (mViewPager.getCurrentItem()) {
case 0:
return (Scrollable) view.findViewById(R.id.castdetailsinfo);
case 1:
return (Scrollable) view.findViewById(R.id.castdetailscredits);
case 2:
return (Scrollable) view.findViewById(R.id.castdetailsbiography);
default:
return (Scrollable) view.findViewById(R.id.castdetailsinfo);
}
}
private Scrollable getCurrentScrollable() {
Fragment fragment = getCurrentFragment();
if (fragment == null) {
return null;
}
View view = fragment.getView();
if (view == null) {
return null;
}
switch (mViewPager.getCurrentItem()) {
case 0:
return (Scrollable) view.findViewById(R.id.TVOnTheAirList);
case 1:
return (Scrollable) view.findViewById(R.id.TVAiringTodayList);
case 2:
return (Scrollable) view.findViewById(R.id.TVPopularList);
case 3:
return (Scrollable) view.findViewById(R.id.TVTopRatedList);
default:
return (Scrollable) view.findViewById(R.id.TVOnTheAirList);
}
}
private Scrollable getCurrentScrollable() {
Fragment fragment = getCurrentFragment();
if (fragment == null) {
return null;
}
View view = fragment.getView();
if (view == null) {
return null;
}
switch (mViewPager.getCurrentItem()) {
case 0:
return (Scrollable) view.findViewById(R.id.moviedetailsinfo);
case 1:
return (Scrollable) view.findViewById(R.id.castList);
case 2:
return (Scrollable) view.findViewById(R.id.moviedetailsoverview);
default:
return (Scrollable) view.findViewById(R.id.moviedetailsinfo);
}
}
@Override
public void onFragmentViewDestroyed(FragmentManager fm, Fragment fragment) {
View view = fragment.getView();
if (view != null) {
refWatcher.watch(view);
}
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
if (fragment instanceof PreferenceFragment && fragment.getView() != null) {
// Set list view padding to 0 so dividers are the full width of the screen.
fragment.getView().findViewById(android.R.id.list).setPadding(0, 0, 0, 0);
}
}
}
public static boolean hideKeyboard(@NonNull Fragment fragment) {
if(fragment.isDetached() || fragment.isRemoving() || null == fragment.getActivity()) return true;
InputMethodManager inputMethodManager = (InputMethodManager) fragment.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
View rootView = fragment.getView();
if(rootView instanceof ViewGroup) {
View focusedChild = ((ViewGroup)rootView).getFocusedChild();
if(null != focusedChild) {
return inputMethodManager.hideSoftInputFromWindow(focusedChild.getWindowToken(), 0);
}
}
return true;
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
if (fragment instanceof PreferenceFragment && fragment.getView() != null) {
// Set list view padding to 0 so dividers are the full width of the screen.
fragment.getView().findViewById(android.R.id.list).setPadding(0, 0, 0, 0);
}
}
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
if (fragment instanceof PreferenceFragment && fragment.getView() != null) {
// Set list view padding to 0 so dividers are the full width of the screen.
fragment.getView().findViewById(android.R.id.list).setPadding(0, 0, 0, 0);
}
}
}
private int getParentId(final Fragment fragment) {
if (fragment.getView() != null && fragment.getView().getParent() != null) {
return ((View) fragment.getView().getParent()).getId();
}
return 0;
}
@Nullable
@Override
public View getView(Fragment fragment) {
return fragment.getView();
}
@Nullable
@Override
public View getView(Fragment fragment) {
return fragment.getView();
}
@Override public Object instantiateItem(ViewGroup container, int position) {
// If we already have this item instantiated, there is nothing
// to do. This can happen when we are restoring the entire pager
// from its saved state, where the fragment manager has already
// taken care of restoring the fragments we previously had instantiated.
if (mFragments.size() > position) {
Fragment f = mFragments.get(position);
if (f != null) {
int newPos = getItemPosition(f);
if (position == newPos) {
if (f.getView() != null && f.getView().getParent() != container) {
((ViewGroup) f.getView().getParent()).removeView(f.getView());
container.addView(f.getView());
}
return f;
} else {
mFragments.remove(position);
mFragments.ensureCapacity(newPos + 1);
for (int i = mFragments.size(); i < (newPos +1); i++) {
mFragments.add(null);
}
mFragments.set(newPos, f);
}
}
}
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
Fragment fragment = getItem(position);
if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
if (mSavedState.size() > position) {
Fragment.SavedState fss = mSavedState.get(position);
if (fss != null) {
fragment.setInitialSavedState(fss);
}
}
while (mFragments.size() <= position) {
mFragments.add(null);
}
fragment.setMenuVisibility(false);
mFragments.set(position, fragment);
mCurTransaction.add(container.getId(), fragment, getTag(position));
return fragment;
}