我正在尝试替换片段内的片段,当我尝试这样做时,我试图替换的片段将被添加到现有片段而不是替换它。我已经尝试了关于堆栈溢出的所有建议和答案,但是每一次努力都是徒劳的。
这是一段代码。
Comments.xml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TheFoody.Models;
using TheFoody.DataAccess;
using System.Web.Security;
using System.Web.Mail;
using System.Net.Mail;
signature.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAppBG"
android:layoutDirection="locale"
android:textAlignment="center"
android:textDirection="locale">
<LinearLayout
android:id="@+id/handover_comments_heading"
android:layout_width="match_parent"
android:layout_height="74dp"
android:layout_below="@id/toolbar"
android:background="@color/colorAccent"
android:orientation="horizontal"
android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/comments"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/handover_comments_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/handover_comments_heading"
android:orientation="vertical"
android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<EditText
android:id="@+id/handover_comments_comments"
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="start"
android:hint="@string/enter_your_comments"
android:maxLength="320"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/handover_comments_textcounter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="end"
android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp"
android:text="0/320" />
<CheckBox
android:id="@+id/handover_comments_checkbox"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:text="Check text"
android:textColor="@color/colorAppTextColor"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:id="@+id/handover_comments_save"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:background="#EC3E45"
android:text="@string/save"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<Button
android:id="@+id/handover_comments_cancel"
android:layout_width="150dp"
android:layout_height="70dp"
android:background="#3B424C"
android:text="@string/cancel"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_marginTop="10dp"
android:background="@color/colorAppBG"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/handover_comments_layout">
<fragment
android:id="@+id/handover_sign_off_base_fragment"
android:name="com.oviyum.fleetfoot.mvp.handover.sign_off.OTPFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_otp" />
</FrameLayout>
</RelativeLayout>
OTPFragment.Java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/colorAppBG"
tools:context="com.oviyum.fleetfoot.mvp.handover.sign_off.SignatureFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="74dp"
android:background="@color/colorAccent"
android:orientation="horizontal"
android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Signature"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
<com.github.gcacace.signaturepad.views.SignaturePad
android:id="@+id/handover_signature_signature_pad"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#FFFFFF"
app:penColor="@android:color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right"
android:paddingEnd="10dp"
android:paddingRight="10dp">
<Button
android:id="@+id/handover_signature_upload_signature"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:background="#EC3E45"
android:padding="10dp"
android:text="Upload Signature"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<Button
android:id="@+id/handover_signature_resend_otp"
android:layout_width="150dp"
android:layout_height="70dp"
android:background="#3B424C"
android:text="RESEND OTP"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="RATE YOUR EXPERIENCE"
android:textSize="20sp" />
<RatingBar
android:id="@+id/handover_signature_experience"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:numStars="5"
android:scaleX="2"
android:scaleY="2" />
<Button
android:id="@+id/handover_signature_submit"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:background="#EC3E45"
android:text="SUBMIT"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
SignatureFrament.Java
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import com.oviyum.fleetfoot.R;
import com.oviyum.fleetfoot.others.ToastHelper;
public class OTPFragment extends Fragment implements View.OnClickListener {
private View view;
private Activity activity;
private Context context;
private Button submitButton;
private Button resendButton;
private EditText enterOTP;
public OTPFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
this.view = inflater.inflate(R.layout.fragment_otp, container, false);
init();
return view;
}
public void init(){
submitButton = (Button)view.findViewById(R.id.handover_otp_submit);
submitButton.setOnClickListener(this);
resendButton = (Button)view.findViewById(R.id.handover_otp_resend_otp);
resendButton.setOnClickListener(this);
enterOTP = (EditText)view.findViewById(R.id.handover_otp_enter_otp);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
this.activity = getActivity();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.handover_otp_submit:
ToastHelper.makeToast("clicked");
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
SignatureFragment llf = new SignatureFragment();
ft.replace(R.id.handover_sign_off_base_fragment, llf);
ft.addToBackStack(null);
ft.commit();
break;
case R.id.handover_otp_resend_otp:
break;
}
}
}