1

최근에 노래를 재생 한 음악 플레이어 재생 목록을 만들고 있습니다. 나는 노래의 arraylist와 공유 환경 설정에서 재생되고있는 노래의 색인을 저장하고있다. 내가 최근에 연주 한 노래를 얻으려고하는 것은 공유 환경 설정에서 arraylist와 노래 색인을 가져 와서 다른 arraylist에 저장하는 것입니다. 그러나 문제는 recyclerView가 한 번에 하나의 노래 만 표시한다는 것입니다.최근에 재생 한 노래를 검색하는 방법은 무엇입니까?

예를 들어, 내가 A 곡을 재생하면 recyclerView가 노래 A를 첫 번째 위치에 표시하고 B 노래를 재생하면 recyclerView가 B 곡을 첫 번째 위치에 표시하고 A 곡을 두 번째 위치에 표시해야합니다. 그러나 그것은 단지 첫 번째 위치를 보여줍니다.

RecentlyPLayedsongs.java

는 :

@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    LayoutInflater inflater = LayoutInflater.from(this); 
    View view6 = inflater.inflate(R.layout.activity_recently_played, null); 
    FrameLayout container6 = (FrameLayout) findViewById(R.id.container); 
    container6.addView(view6); 

    recyclerView_recently_played = findViewById(R.id.recyclerView_recently_played); 

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext()); 
    recyclerView_recently_played.setLayoutManager(linearLayoutManager); 

    StorageUtil storageUtil2 = new StorageUtil(getApplicationContext()); 

    SongList=storageUtil2.loadAudio(); 

    pos = storageUtil2.loadAudioIndex(); 

    songInfoModel = SongList.get(pos); 

    RecentlyPlayedList.add(songInfoModel); 

    adapter1 = new Playlist_Recently_Added_Adapter(RecentlyPlayedList, getApplicationContext()); 
    recyclerView_recently_played.setAdapter(adapter1); 

} 
+0

이는 노래 b가 재생 될 때 배열의 두 번째 위치에 추가한다는 의미입니까? –

+0

노래 B가 연주 될 때 노래 A가 두 번째 위치에 추가되고 노래 B가 일반 음악 플레이어처럼 첫 번째 위치에 추가되기를 원합니다. – Rektirino

답변

0

당신은 당신이 시간에 따라 정렬 할 필요가있는 노래 목록을 통과하기 전에 두 가지 방법 중 하나

  1. 다음을 통해이 작업을 수행 할 수 있습니다. 이 경우 노래를 재생할 때도 시간을 절약해야합니다. (이를 달성하려면 많은 코딩과 유지 관리가 필요합니다.)
  2. 이것은 훨씬 쉬운 방법입니다. add() 배열 목록의 메소드를 사용할 수 있으며 아래 코드에서 언급 된 위치를 지정할 수 있습니다.

    list.add (o, currentSong);

0은 0 지수에서 추가되는 노래를 재생할 때마다 항상 전달되는 최신 곡을 의미합니다. 희망은 당신을 도와줍니다.

참고 : 나는

List<Integer> list = new ArrayList(); 
    list.add(1); 
    list.add(2); 
    list.add(3); 

    Log.d(TAG, "firs time"); 
    for (int a=0; a < list.size();a++) { 
     Log.d(TAG, "" + list.get(a)); 
    } 

    list.add(0,4); 

    Log.d(TAG, "second time"); 
    for (int a=0; a < list.size();a++) { 
     Log.d(TAG, "" + list.get(a)); 
    } 

로그가

11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: firs time 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 1 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 2 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 3 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: second time 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 4 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 1 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 2 
11-19 11:24:53.400 3681-3681/com.example.awaheed.datetime D/test: 3 

아래 두 번째 번호의 로그를 살펴 추가 된 가지고 언급 한 바와 같이 예상대로 작동 아래의 코드를 사용하여 두 번째 솔루션을 확인했습니다 '0'인덱스에서 첫 번째 위치에 있고 remaing 항목이 푸시 다운되지 않습니다. 희망이 어떤 의미가 있습니다.

+0

내가 말했듯이, 나는 arraylist의 add() 메소드를 사용하고 있지만 최근 노래를 첫 번째 장소에 추가합니다. 이전 노래는 recyclerView에 아래에 표시되지 않습니다. 당신이 나의 요점을 얻고 있기를 바랍니다. – Rektirino

+0

내가 언급했듯이, 나는 add 메소드를 사용하고 있지만 위치를 지정해도 그렇게하려고하면 처음 위치에 노래를 추가하고 나머지 노래는 첫 번째 노래 아래로 자동으로 푸시됩니다. 시도 해봐. 그때 알려주세요 –

+0

나는 그것을 전에 시도했습니다. 성공하지 못했습니다. 노래 만 추가됩니다. – Rektirino