在我的应用程序中我的第一个Fragment是在BackStack中,并且在交易时没有将该片段添加到backstack.
编辑.
我在第一次横切后多次使用相同的碎片,但横切后跟第一个被添加到backstack
addToBackStack(TAG);但我从未添加第一个碎片到backstack但仍然我不明白为什么我必须点击两次将应用程序发送到后台.
这是代码
FragmentManager fm = getSupportFragmentManager();
Bundle args = new Bundle();
args.putString("url", Constants.URL_BASE);
feedFragment.setArguments(args);
fm.beginTransaction().replace(R.id.content_frame, feedFragment).commit();
Run Code Online (Sandbox Code Playgroud)
现在,当我按下后退按钮时,它会删除片段,但应用程序不会转到后台.当我第二次按下后退按钮时,它会进入后台.
它replace()本身是否将片段添加到backstack?如果是,那么我如何删除片段并让我的应用程序转到后台onBackPressed?如果它没有将片段添加到backstack那么为什么会发生这种情况?我该如何让它正常工作?
谢谢!
编辑:
这是完整的活动代码.
public class MainActivity extends AppCompatActivity {
private final String TAG = getClass().getName();
private DrawerLayout drawerLayout;
private FeedFragment feedFragment = new FeedFragment();
private ListView listView;
private LinearLayout searchLayout;
private RelativeLayout logolayout;
private Toolbar toolbar;
private Button settingBtn;
private Button bookmarkBtn;
private Button searchBtn;
private Tracker mTracker;
@Override
protected void onCreate(Bundle …Run Code Online (Sandbox Code Playgroud) 我正在使用Dagger,我有一个带有@Singleton范围的app组件,还有一个带有@Singleton范围的子组件.现在,当我编译它时,我收到此错误:
[io.droid.nowtellapp.dagger.SignInMvpComponet] io.droid.nowtellapp.dagger.SignInMvpComponet有相互冲突的范围:io.droid.nowtellapp.dagger.ApplicationComponent也有@Singleton
要解决此错误,我@Singleton从子组件中删除并编译它,这次出现此错误:
错误:(12,1)错误:io.droid.nowtellapp.dagger.SignInMvpComponet(unscoped)可能不引用范围绑定:@Singleton @Provides io.droid.nowtellapp.mvp.SignInMvp.Presenter io.droid.nowtellapp.dagger. SignInMvpModule.presenter(io.droid.nowtellapp.webservices.NowTellApi)
也出现此错误:
错误:(21,8)错误:[ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor无法处理此类,因为并非所有依赖项都可以解析.使用生成的代码检查编译错误或循环依赖性.
这是我的ApplicationComponent
@Singleton
@Component(modules = {AppModule.class, RetroApiModule.class})
public interface ApplicationComponent {
void inject(MainActivity mainActivity);
SignInMvpComponet signInMvpComponet(SignInMvpModule signInMvpModule);
}
Run Code Online (Sandbox Code Playgroud)
这是我的SignInMvpComponet
@Subcomponent(modules = {SignInMvpModule.class})
public interface SignInMvpComponet {
void inject(SignInFragment signInFragment);
Run Code Online (Sandbox Code Playgroud)
这是SignInMvpModule类
@Module
public class SignInMvpModule {
private final SignInMvp.View view;
public SignInMvpModule(SignInMvp.View view) {
this.view = view;
}
@Singleton
@Provides
SignInMvp.Presenter presenter(NowTellApi api) {
return new SignInPresenter(view,api);
}
}
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?提前致谢.
苦苦于xml.我想显示RoundedCornerImageView在CardView的底部.很难实现它.
这是我想要布局的样子
这是xml我到目前为止所尝试的内容.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/card"
android:orientation="vertical">
<LinearLayout
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is Title"
android:textSize="24sp"
android:textColor="#000"/>
<TextView
android:padding="5dp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#c5c5c5"
android:text="This is content.This is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis is contentThis …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用中实现共享转换.我希望在RecyclerView中的ImageView将出现在下一个片段中,以便从RecyclerView到片段进行共享转换.但它没有用.我是怎么做到的.
Recycler的项目布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_cover"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:transitionName="cover"
android:src="@drawable/ic_check_circle" />
<View
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#30000000" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/tv_title"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/colorPrimary"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="BBC"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
android:textColor="#fff"
android:textSize="16dp" />
<TextView
android:id="@id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/colorPrimary"
android:maxLines="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="NEWS TITLE"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="#fff"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
片段布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_cover"
android:transitionName="cover"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我使用firebase作为后端服务.我正在将数据插入我的firebase数据库,并使用以下代码检查插入是否成功,但它总是返回false.
boolean issucessfull = ref.child("universities").setValue(university).isSuccessful();
if (issucessfull) {
Toast.makeText(UniversityActivity.this, "added to database successfully", Toast.LENGTH_SHORT).show();
clearViews();
enableViews(true);
} else {
Toast.makeText(UniversityActivity.this, "Some error occured, try again", Toast.LENGTH_SHORT).show();
enableViews(true);
}
Run Code Online (Sandbox Code Playgroud)
可能是什么原因?我已调试它数据已被添加到firebase但它仍然是假的.任何帮助将不胜感激.
我正在使用recyclelerview和staggeredGridLayoutManager.我想要做的是在第一行显示一个标题项.然后我想在下面每行显示2个项目.但我无法这样做.
这是我用过的代码.
recyclerView = (RecyclerView)findViewById(R.id.recycler);
staggeredGridLayoutManager = new StaggeredGridLayoutManager(1,1);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
Run Code Online (Sandbox Code Playgroud)
这些都是结果
帮助我.谢谢
我已将按钮的可见性设置为“消失”,但是现在当我想将按钮设置为可见时,尝试设置按钮的可见性时出现以下错误
@Bind(R.id.btn1)
Button btn1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.hifragment_main, container, false);
if(1==1)
{
btn1.setVisibility(View.VISIBLE);
}
return view;
}
Run Code Online (Sandbox Code Playgroud)