java http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html相关的知识,希望对你有一定的参考价值。
/**
* Created by weiyi.li on 4/7/16.
* This activity includes {@link AlbumFragment} and {@link ThumbnailFragment}.
*/
public class TwoFragmentsActivity extends BasicOperationActivity {
private boolean mShowingThumbnail = true;
@Dvr.DvrFolder private int mFolderType = Dvr.DVR_FOLDER_LOOPED_VIDEOS;
private FragmentManager mFm;
private AlbumFragment mAlbumFragment;
private ThumbnailFragment mThumbnailFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActionTitleView.setOnClickListener(mOnActionTitleClickedListener);
mFm = getSupportFragmentManager();
showThumbnailFragment(mFolderType);
}
@NonNull
@Override
protected Fragment createContentFragment() {
return null;
}
@Override
protected void onOperationButton1Clicked() {
}
@Override
protected void onOperationButton2Clicked() {
}
/** Implements listeners to response to UI touch events. */
private DebouncedOnClickListener mOnActionTitleClickedListener = new DebouncedOnClickListener() {
@Override
public void onDebouncedClick(View v) {
if (mShowingThumbnail) {
showAlbumFragment();
hideThumbnailFragment();
} else {
hideAlbumFragment();
showThumbnailFragment(mFolderType);
}
}
};
private AlbumFragment.OnAlbumClickListener mOnAlbumClickListener = new AlbumFragment.OnAlbumClickListener() {
@Override
public void onAlbumClick(@Dvr.DvrFolder int folder) {
mFolderType = folder;
mShowingThumbnail = true;
hideAlbumFragment();
showThumbnailFragment(folder);
}
};
/** Private methods to update UI */
private void showThumbnailFragment(@Dvr.DvrFolder int folder) {
if (mThumbnailFragment == null) {
mThumbnailFragment = ThumbnailFragment.newInstance(folder);
mFm.beginTransaction().add(R.id.contentFragmentContainer, mThumbnailFragment).commit();
}
mFm.beginTransaction().show(mThumbnailFragment).commit();
}
private void hideThumbnailFragment() {
if (mThumbnailFragment != null) {
mFm.beginTransaction().hide(mThumbnailFragment).commit();
}
}
private void showAlbumFragment() {
if (mAlbumFragment == null) {
mAlbumFragment = new AlbumFragment();
mAlbumFragment.setOnAlbumClickListener(mOnAlbumClickListener);
mFm.beginTransaction().add(R.id.contentFragmentContainer, mAlbumFragment).commit();
}
mFm.beginTransaction().show(mAlbumFragment).commit();
}
private void hideAlbumFragment() {
if (mAlbumFragment != null) {
mFm.beginTransaction().hide(mAlbumFragment).commit();
}
}
}
以上是关于java http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html的主要内容,如果未能解决你的问题,请参考以下文章
Java 布尔运算
java [Java] Java常用代码#java
Java - 35 Java 实例
Java While 循环
Java 字符串
Java If ... Else