quiero abrir un fragment al seleccionar un Item del Bottom Navigation que creé, pero el código siguiente es el que no me deja continuar por que aparece erroneo en el fragment antes del fragment.getTag y no se como solucionarlo. GRACIAS
(R.id.contentLayout, fragment, fragment.getTag()).commit();
aquí mi código completo :
MainActivity.java
bottomNavigationView =(BottomNavigationView) findViewById(R.id.bottom_navegation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (item.getItemId()== R.id.consultaItem){
citaFragment fragment = new citaFragment();
android.app.FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.contentLayout,
//aquí tengo el error -> fragment,
fragment.getTag()).commit();
}
else if (item.getItemId()== R.id.inicioItem) {
mensajeRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
infoTextView.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return true;
}
else if (item.getItemId() == R.id.ubicacionItem) {
//infoTextView.setText(R.string.precio);
return true;
}
return false;
}
});
fragment_cita
<android.support.constraint.ConstraintLayout 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"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
tools:context="com.example.a60393.example.citaFragment">
<!-- TODO: Update blank fragment layout -->
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"/>
<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="395dp"
android:layout_height="120dp"
card_view:cardCornerRadius="6dp"
android:layout_marginTop="60dp"
card_view:cardElevation="10dp"
card_view:cardUseCompatPadding="true"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp">
<TextView
android:id="@+id/citaTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Cita:"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
android:textAlignment="center"
android:textSize="35dp"/>
<TextView
android:id="@+id/horaFechaTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:text="@string/_12_mayo_2017"
android:textStyle="bold"
android:textColor="424242"
android:textAlignment="center"
android:textSize="20dp"/>
</android.support.v7.widget.CardView>