R
R
rafaelSalihov2019-12-14 18:49:08
Java
rafaelSalihov, 2019-12-14 18:49:08

Is there such a function to replace id in view android studio?

For example, to replace the text, the setText function is used, to replace the path to the image setImageResource, but is there one for the id?
I have a task to display a list. It has a word, then pictures, and so in a row.
word
picture
word
picture
word
picture
By clicking on the picture, the mp3 file for this word should be played, as it is read sounds. If I display the pictures in a list, as I understand, they all have the same id, if I click on the picture, I need each picture to have its own unique id, since the function, when clicked, will know which mp3 to play by the id of the clicked picture.
public void onClick(View view) {
switch (view.getId()) {
case R.id.imageView1:
soundPlay(MediaPlayer1);
break;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-12-14
@rafaelSalihov

If it's a list, then use RecyclerView. There will be a list of data to display. This list will contain IDs (but not the ID of the view or other resource, but the ID of the data. For example, a serial number). Orient yourself to them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question