When I click the PLAY button in Activity, I want to get some data in RECYCLERVIEW (For example, Song1, Song2, Song3.. data). How can I do that? Can you help with the code? I'm new at this. Here are my codes:
This is Model:
public class MyModel {
String songName, songURL;
public MyModel(String _songName, String _songURL) {
this.songName = _songName;
this.songURL = _songURL;
}
// Getters and setters
}
This is a Adapter:
public class MyAdaptor extends RecyclerView.Adapter<MyAdaptor.MyHolder> {
ArrayList<MyModel> ayetList;
LayoutInflater layoutInflater;
Context mContext1;
View view;
public MyAdaptor(Context mContext, ArrayList<MyModel> _ayetList) {
this.ayetList = _ayetList;
mContext1 = mContext;
layoutInflater = LayoutInflater.from(mContext);
}
public class MyHolder extends RecyclerView.ViewHolder {
TextView tv_songname;
SeekBar sb_song;
public MyHolder(@NonNull View itemView) {
super(itemView);
tv_songname = itemView.findViewById(R.id.tv_songname);
sb_song = itemView.findViewById(R.id.sb_song);
}
public void setData(MyModel ayetModel, int pozisyon) {
tv_songname.setText(ayetModel.getSongName());
}
}
@NonNull
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
view = layoutInflater.inflate(R.layout.song_item, parent, false);
return new MyHolder(view);
}
public void onBindViewHolder(@NonNull MyHolder holder, int position) {
MyModel selectedProduct = ayetList.get(position);
holder.setData(selectedProduct, position);
}
public int getItemCount() {
return ayetList.size();
}
}
This is the part I want to process. Here I want to get the data from the recyclerview by clicking the PLAY button.
This is a Activity:
Button btnPlay;
RecyclerView rwSongs;
Context context = this;
MyAdaptor myAdaptor;
MyModel myModel;
ArrayList<MyModel> mainList = new ArrayList<>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
btnPlay = findViewById(R.id.btnPlay);
rwSongs = findViewById(R.id.rwSongs);
rwSongs.setLayoutManager(new LinearLayoutManager(context));
getData();
img_Play.setOnClickListener(view -> {
//I don't know what to do next ...
});
}
private void getData() {
.
.
.
for (int i = 0; i < _dataArrayItiraf.length(); i++) {
JSONObject jsonItiraf = _dataArrayItiraf.getJSONObject(i);
String _SongName = jsonItiraf.getString("SongName");
String _SongURL = jsonItiraf.getString("SongURL");
myModel = new MyModel(_SongName, _SongURL);
myModel.setSongName(_SongName);
myModel.setSongURL(_SongURL);
mainList.add(myModel);
}
myAdaptor = new MyAdaptor(context, mainList);
rwSongs.setAdapter(myAdaptor);
.
.
.
}
I will look forward to all your help. Thanks...