Codigo Fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View vista = inflater.inflate( R.layout.tab3_fragment, container, false );
// loadLanguage();
// setContentView( R.layout.activity_final );
// return new FinalActivity(this);
// UI
layout = vista.findViewById( R.id.layout_VoteAct );
mTitle = vista.findViewById( R.id.tvTitulo );
mDescription = vista.findViewById( R.id.tvDescripcion );
mCode = vista.findViewById( R.id.tvCodigo );
mImage = vista.findViewById( R.id.imageView2 );
Si = vista.findViewById( R.id.btnYes );
No = vista.findViewById( R.id.btnNo );
Nose = vista.findViewById( R.id.btnSoSo );
Delete = vista.findViewById( R.id.btn_DeleteEvent );
compartir = vista.findViewById( R.id.tv_contador );
calendario = vista.findViewById( R.id.tv_calendar );
calendar = vista.findViewById( R.id.bt_calendar );
//prueba=findViewById( R.id.tv_prueba );
rv = vista.findViewById( R.id.recycler );
//cont=findViewById( R.id.tv_contador );
dias = vista.findViewById( R.id.tv_diasrestantes );
// Intent
code = getActivity().getIntent().getExtras().getString("code");
dataEventIntent = getActivity().getIntent().getExtras().getString("data");
guri = getActivity().getIntent().getExtras().getString("uri");
random = getActivity().getIntent().getExtras().getString("random");
// Intent intent = getIntent();
/*
code = intent.getStringExtra( "code" );
dataEventIntent=intent.getStringExtra( "data" );
guri=intent.getStringExtra( "uri" );
random=intent.getStringExtra( "random" );
*/
// Habilitar el modo OffLine de la BBDD
if (FirebaseApp.getApps( getActivity() ).isEmpty()) {
FirebaseApp.initializeApp( getActivity() );
FirebaseDatabase.getInstance().setPersistenceEnabled( true );
}
mDatabase = FirebaseDatabase.getInstance().getReference().child( "Events" ).child( code );
mDatabase.addValueEventListener( new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Event event = dataSnapshot.getValue( Event.class );
mTitle.setText( event.getTitle() );
mDescription.setText( event.getDescription() );
// prueba.setText( event.getDateEvent() );
dataEvent=event.getDateEvent();
code=event.getCode();
url=event.getFoto();
mCode.setText(event.getCode());
ano=event.getAno();
mes=event.getMes();
dia=event.getDia();
countDate();//diferencia fechas
url();//foto evento
}
@Override
public void onCancelled(final DatabaseError databaseError) {
}
} );
user = FirebaseAuth.getInstance().getCurrentUser();
//RecyclerView
FirebaseDatabase database=FirebaseDatabase.getInstance();
usuarios=new ArrayList<>( );
rv.setLayoutManager( new LinearLayoutManager( getActivity() ) ); //FALLO RV RECIBE NULL
adapter=new Adapter( usuarios );
rv.setAdapter( adapter );
database.getReference("Events").child( code ).child( "Users" ).addValueEventListener( new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
usuarios.removeAll( usuarios );
for (DataSnapshot snapshot:dataSnapshot.getChildren()) {
User user=snapshot.getValue(User.class) ;
usuarios.add( user );
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
} );//cada vez que se cambien datos se refresca
countVote();
return vista;
}