替换活动中的片段



我得到了这个错误:

No view found for id 0x7f09005b (com.banorte.bepmovil:id/frame) for fragment TransferenciaTercerosFragment{1d548d3 #2 id=0x7f09005b terceros}

我所拥有的是一个使片段膨胀的活动,稍后我想将该片段(1(替换为另一个片段(2(。

因此,在片段MenuTransFragment(1(中的代码将其更改为TransferenciaTerceroSFraction(2(,代码是这样的:

private void loadHomeFragment() {
Runnable mPendingRunnable = new Runnable() {
@Override
public void run() {
// update the main content by replacing fragments
Fragment fragment = getFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(android.R.anim.fade_in,
android.R.anim.fade_out);
fragmentTransaction.replace(R.id.frame, fragment, CURRENT_TAG);
//LinearLayout = LinearLayout

fragmentTransaction.commitAllowingStateLoss();
}
};
// If mPendingRunnable is not null, then add to the message queue
if (mPendingRunnable != null) {
mHandler.post(mPendingRunnable);
}
}

geatFragment((基本上就是这样做的:

TransferenciaTercerosFragment homeFragment = TransferenciaTercerosFragment.newInstance("si","we");

碎片

如何将实际片段替换为另一个片段?

注意。最初,为了向片段MenuTransFragment(1(收费,我有一个使用loadHomeFragment(方法的活动。

public class ResumenActivity extends AppCompatActivity
implements AllAccountsFragment.OnFragmentInteractionListener,
AutorizacionesFragment.OnFragmentInteractionListener,
OperacionesFragment.OnFragmentInteractionListener,
TransferenciaTercerosFragment.OnFragmentInteractionListener {

@哈姆雷特莱昂

这是第二个片段onCreateView的代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_transf_terceros, container, false);
}

这是fragment_transfer_terceros:的代码

<?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="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#F1F1F1"
tools:context=".fragment.TransferenciaTercerosFragment">
<RelativeLayout
android:layout_width="320dp"
android:layout_height="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="60dp"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:textColor="@color/colorPrimary"
android:gravity="center_vertical"
android:text="DATOS DE LA TRANSFERENCIA" />
</RelativeLayout>
<RelativeLayout
android:layout_width="320dp"
android:layout_height="420dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="100dp"
android:background="#FFFFFF"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/colorPrimary"
android:text="Cuenta Origen" />
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="@+id/ddlOrigen"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:background="@layout/spinner_border">
</com.toptoche.searchablespinnerlibrary.SearchableSpinner>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/colorPrimary"
android:text="Cuenta Destino" />
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="@+id/ddlDestino"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:background="@layout/spinner_border">
</com.toptoche.searchablespinnerlibrary.SearchableSpinner>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/colorPrimary"
android:text="Importe" />
<EditText
android:id="@+id/txtimporte"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="145dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:inputType="numberDecimal"
android:maxLines="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:textSize="15dp"
android:textCursorDrawable="@color/colorCursor"
android:background="@layout/border"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="170dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/colorPrimary"
android:text="Número de Referencia" />
<EditText
android:id="@+id/txtreferencia"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="195dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:inputType="number"
android:maxLines="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:textSize="15dp"
android:textCursorDrawable="@color/colorCursor"
android:background="@layout/border"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="220dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/colorPrimary"
android:text="Concepto de Pago" />
<EditText
android:id="@+id/txtconcepto"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="245dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:maxLines="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:textSize="15dp"
android:textCursorDrawable="@color/colorCursor"
android:background="@layout/border"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="270dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textColor="@color/colorPrimary"
android:text="Fecha de aplicación" />
<TextView
android:id="@+id/txtfecha"
android:layout_width="300dp"
android:layout_height="25dp"
android:layout_marginTop="295dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:background="#F1F1F1" />
<ImageView
android:id="@+id/continua_button"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_marginTop="340dp"
android:layout_marginStart="190dp"
android:layout_marginLeft="190dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/btncontinuar" />

</RelativeLayout>

</FrameLayout>

对我有效的是:

TransferenciaTercerosFragment homeFragment = TransferenciaTercerosFragment.newInstance("si","we");
((ResumenActivity)getActivity()).loadHomeFragment(homeFragment);

修改homeFragment以接收活动中的片段并替换它。

最新更新