, когда я нажимаю «просмотр видео лекции» в моей основной деятельности, это открывает пустое действие, не показывая никаких видео, я уже добавил видео непосредственно в базу данных и хранилище консоли firebase, я не знаю, почему это не так показанный в моем обзоре переработчика.
Ниже приведены некоторые файлы кода:
MainActivity.java
package com.example.android.myapplication;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
Button button1;
Button button2;
Button button3;
Button button4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
button1= (Button)findViewById( R.id.d );
button2= (Button)findViewById( R.id.C2 );
button3= (Button)findViewById( R.id.C3 );
button4= (Button)findViewById( R.id.C4 );
button1.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout c1=(LinearLayout)findViewById( R.id.c1);
c1.setVisibility( c1.getVisibility()==View.VISIBLE? View.GONE: View.VISIBLE );
}
} );
button2.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout c2=(LinearLayout)findViewById( R.id.c2);
c2.setVisibility( c2.getVisibility()==View.VISIBLE? View.GONE: View.VISIBLE );
}
} );
button3.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout c3=(LinearLayout)findViewById( R.id.c3);
c3.setVisibility( c3.getVisibility()==View.VISIBLE? View.GONE: View.VISIBLE );
}
} );
button4.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout c4=(LinearLayout)findViewById( R.id.c4);
c4.setVisibility( c4.getVisibility()==View.VISIBLE? View.GONE: View.VISIBLE );
}
} );
}
//ADDED
public void OpenVideosActivity(View view){
Intent intent= new Intent(this,VideoLectures.class);
startActivity( intent );
}
}
над моей функцией OpenVideosActivity () открывает пустое действие
RecyclerViewAdapter.java
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
Context context;
List<Model> models;
public RecyclerViewAdapter(Context context, List<Model> TempList){
this.models=TempList;
this.context=context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View view= LayoutInflater.from( parent.getContext() ).inflate( R.layout.video_lectures,parent,false );
ViewHolder viewHolder= new ViewHolder( view );
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position){
Model model=models.get(position);
Uri uri= Uri.parse( model.getVideo() );
holder.videoView.setVideoURI( uri );
}
@Override
public int getItemCount(){
return models.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public VideoView videoView;
public ViewHolder(@NonNull View itemView) {
super( itemView );
videoView=(VideoView) itemView.findViewById( R.id.video_view );
}
}
}
VideoLectures.java
RecyclerView recyclerView;
FirebaseDatabase firebaseDatabase;
List<Model> list = new ArrayList<>();
DatabaseReference mref;
RecyclerView.Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.video_lectures );
recyclerView=(RecyclerView) findViewById( R.id.recycler_view );
recyclerView.setHasFixedSize( true );
//set layout as linearlayout
recyclerView.setLayoutManager( new LinearLayoutManager( this ) );
//send query to firebasedatabase
firebaseDatabase=FirebaseDatabase.getInstance();
mref=firebaseDatabase.getReference("Data");
mref.addValueEventListener( new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren()){
Model model=dataSnapshot1.getValue(Model.class);
list.add( model );
}
adapter = new RecyclerViewAdapter( VideoLectures.this, list );
recyclerView.setAdapter( adapter );
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
} );}}
Model.java
String video;
//constructor
public Model(){}
//getter and setter prs alt+ Insert
public void setVideo(){
this.video=video;
}
public String getVideo(){
return video;
}
}
это xml файлы
video_lectures.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
videos_lecture_item.xml
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardElevation="3dp"
android:layout_margin="8dp">
<!-- <FrameLayout
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">-->
<VideoView
android:layout_width="match_parent"
android:id="@+id/video_view"
android:layout_height="400dp" />
<!-- </FrameLayout>-->
<!--remeember to add progress bar when loading-->
</androidx.cardview.widget.CardView>
Пожалуйста, помогите мне