Hi I made a random page with text and image now, I want to add mp3 files in it.when I click my fab button. there is appear text, image but when I add mp3 files like my codes, it gives an error and my application stop. is there any way to add raw files in shufflefacts? here is my facts.java codes:
public class Facts {
private int ivImage;
private String mFact;
private int videoView;
public Facts(int ivImage, int videoView, String mFact) {
this.ivImage = ivImage;
this.videoView = videoView;
this.mFact = mFact;
}
public int getivImage() {
return ivImage;
}
public int getvideoView() {
return videoView;
}
public String getmFact() {
return mFact;
}
public String videoView() {
return null;
}
}
and here is my random.class:
Toolbar mToolbar;
RecyclerView mRecyclerView;
ImageView mFlower;
TextView mDescription;
VideoView videoView;
private FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
ActionBar actionBar= getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mToolbar = findViewById(R.id.toolbar);
videoView = findViewById(R.id.videoView);
mToolbar.setTitle(getResources().getString(R.string.cv));
mRecyclerView = findViewById(R.id.recyclerview);
mFlower = findViewById(R.id.ivImage);
mDescription = findViewById(R.id.tvDescription);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setImageResource(R.drawable.vbn);
showRandomFact();
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showRandomFact();
}
});
}
private void showRandomFact() {
shuffleFacts();
mFlower.setImageResource(factArray[0].getivImage());
videoView.setVideoPath(factArray[0].videoView());
mDescription.setText(factArray[0].getmFact());
}
Facts f01 = new Facts(R.drawable.a, R.raw.b,"hjgbfvjhsdbfvskhbsdıkfvsdkb");
Facts f02 = new Facts(R.drawable.aa, R.raw.b,"hjgbfvjhsdbfvskhbsdıkfvsdkb");
Facts f03 = new Facts(R.drawable.aas, R.raw.b,"hjgbfvjhsdbfvskhbsdıkfvsdkb");
Facts[] factArray = new Facts[] {
f01,f02,f03
};
public boolean shuffleFacts(){
Collections.shuffle(Arrays.asList(factArray));
return true;
}
}
Aucun commentaire:
Enregistrer un commentaire