0

오디오 플레이어를 만들고 있는데 오디오 파일이 들어있는 모든 폴더에 대해 전화의 내부 저장소를 쿼리하는 "내 파일"조각이 있습니다. 내가 한 것은 "내 파일"조각에 있습니다 (recyclerView에 있음). 이 recyclerView의 항목 (폴더)을 클릭하면 클릭 한 폴더의 오디오 파일을 표시하는 다른 활동 (MyFilesSong.java)이 시작됩니다.동일한 recyclerView에있는 두 명의 다른 arraylists의 항목을 표시하는 방법은 무엇입니까?

내가 원하는 것은 - 폴더를 표시하기 위해 "내 파일"조각을 만들고 싶습니다 (이미있는 것처럼). 그리고 항목 (폴더)을 클릭하면 오디오 파일을 같은 조각에로드해야합니다. 이것에 대한 또 다른 활동을 원함). 나는 분명히 희망한다.

PS : 두 recyclerviews가 사용되며, 이들 모두가 상이한 종류 - "MyFiles"의 ArrayList를이 "는 Songs.java는"제 GIF (내)에 songinfomodel

를 사용하면서 상품을 클릭 foldermodel을 사용하는 새로운를 개방 활동. 그러나 나는 첫 번째 구현 된 것을 원한다. 조각에는 폴더가 표시되고 폴더를 클릭하면 오디오 파일이 표시됩니다.

MyFiles.java :

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.my_files_activity, container, false); 



    recyclerView= view.findViewById(R.id.recyclerView_files); 
    pathTextView= view.findViewById(R.id.myFilesPath); 

    myList = new ArrayList<Object>(); 

    linearLayoutManager=new LinearLayoutManager(getContext()); 
    recyclerView.setLayoutManager(linearLayoutManager); 






    Songpath = SongPath(); 

    for(int i = 0; i<Songpath.size();i++) { 

     Log.e("Paths: ", Songpath.get(i)); 

     file = new File( Songpath.get(i)) ; 

     try { 
      sforFolders = new FolderModel(file.getParentFile().getName(),file.getParentFile().getCanonicalPath()); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     myList.add(sforFolders); 



    } 

    myFilesAdapter = new MyFilesAdapter(getContext(), new MyFilesAdapter.MyFilesItemClickListener() { 
     @Override 
     public void folderonclicklistener(FolderModel name, int position) { 

      Toast.makeText(getContext(), "Folder Name: "+name.getFolderName()+" Position: "+position, Toast.LENGTH_SHORT).show(); 

      Intent i = new Intent(getContext(),MyFilesSongs.class); 
      i.putExtra("parentPath",name.getFolderPath()); 
      startActivity(i); 


     } 
    }); 

    recyclerView.setAdapter(myFilesAdapter); 
    myFilesAdapter.getFilesFolders(myList); 
    myFilesAdapter.notifyDataSetChanged(); 







    return view; 
    } 

MyFilesAdapter.java :

public class MyFilesAdapterFinal extends RecyclerView.Adapter<MyFilesAdapterFinal.ViewHolder> { 

ArrayList<FolderModel> SongParentPath = new ArrayList<>(); 
Context context; 
itemClickListener listener; 

public MyFilesAdapterFinal(ArrayList<FolderModel> songParentPath, Context context,itemClickListener listener) { 
    SongParentPath = songParentPath; 
    this.context = context; 
    this.listener = listener; 
} 

@Override 
public MyFilesAdapterFinal.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

    View v = LayoutInflater.from(context).inflate(R.layout.row_myfiles,parent,false); 

    return new ViewHolder(v); 
} 

@Override 
public void onBindViewHolder(MyFilesAdapterFinal.ViewHolder holder, int position) { 

    FolderModel name = SongParentPath.get(position); 

    holder.rowtext.setText(String.valueOf(name.getFolderName())); 
    holder.bind(name,listener); 





} 

@Override 
public int getItemCount() { 
    return (SongParentPath==null)? 0 : SongParentPath.size(); 
} 

public class ViewHolder extends RecyclerView.ViewHolder { 

    TextView rowtext; 

    public ViewHolder(View itemView) { 
     super(itemView); 

     rowtext = itemView.findViewById(R.id.rowtext); 
    } 

    public void bind(final FolderModel name, final itemClickListener listener) { 

     itemView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       listener.onClick(name,getLayoutPosition()); 
      } 
     }); 
    } 
} 

public interface itemClickListener{ 

    void onClick(FolderModel name, int position); 
} 

Songs.java : (오디오 파일을 나열 활동) :

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

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



    recyclerView = findViewById(R.id.recyclerView); 
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext()); 
    recyclerView.setLayoutManager(linearLayoutManager); 

    String parentPath = getIntent().getExtras().getString("parentPath"); 

    SongList = displayFolderFiles(parentPath); 



    songAdapter = new SongAdapter(getApplicationContext(), SongList, new SongAdapter.RecyclerItemClickListener() { 
     @Override 
     public void onClickListener(SongInfoModel song, int position) { 




      Toast.makeText(getApplicationContext(), song.getSongName(), Toast.LENGTH_SHORT).show(); 


      BaseActivity.setsongText(song); 
      BaseActivity.ButtonPause(); 
     //  playAudio(position); 
      BaseActivity.slidingUpPanelCollapsed(); 





     } 

     @Override 
     public void onLongClickListener(final SongInfoModel song, final int position, View v) { 



      // AddToPlayListDialog(song, v); 


     } 


    }); 


    recyclerView.setAdapter(songAdapter); 

} 

SongsAdapter.java :

 public class SongAdapter extends RecyclerView.Adapter<SongAdapter.SongHolder> { 

ArrayList<SongInfoModel> SongList = new ArrayList<>(); 
Context context; 
private RecyclerItemClickListener listener; 








public SongAdapter(Context context, ArrayList<SongInfoModel> SongList, RecyclerItemClickListener listener) { 

    this.context = context; 
    this.SongList = SongList; 
    this.listener = listener; 

} 




@Override 
public SongAdapter.SongHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view = LayoutInflater.from(context).inflate(R.layout.row_song, parent, false); 
    return new SongHolder(view); 
} 

@Override 
public void onBindViewHolder(final SongAdapter.SongHolder holder, final int position) { 



     final SongInfoModel songInfoModel = SongList.get(position); 


     holder.songName.setText(songInfoModel.SongName); 
     holder.artistName.setText(songInfoModel.ArtistName); 
     holder.duration.setText(String.valueOf(songInfoModel.duration)); 
     String duration = Utility.convertDuration(songInfoModel.getDuration()); 
     holder.duration.setText(duration); 
     Picasso.with(context).load(songInfoModel.getAlbumIDArtwork()).placeholder(R.drawable.ic_launcher).into(holder.iv_artwork); 
     holder.bind(songInfoModel, listener); 






} 

@Override 
public int getItemCount() { 
    return SongList.size(); 
} 

public class SongHolder extends RecyclerView.ViewHolder { 
    TextView songName; 
    TextView artistName; 
    TextView duration; 
    private ImageView iv_artwork; 



    public SongHolder(View itemView) { 

     super(itemView); 
     songName = (TextView)itemView.findViewById(R.id.SongName); 
     artistName= (TextView)itemView.findViewById(R.id.ArtistName); 
     duration = (TextView) itemView.findViewById(R.id.duration); 
     iv_artwork = (ImageView) itemView.findViewById(R.id.iv_artwork); 


    } 

    public void bind(final SongInfoModel songInfoModel, final RecyclerItemClickListener listener) { 
     itemView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       listener.onClickListener(songInfoModel, getLayoutPosition()); 

      } 
     }); 

     itemView.setOnLongClickListener(new View.OnLongClickListener() { 

      @Override 
      public boolean onLongClick(View view) { 

       listener.onLongClickListener(songInfoModel, getLayoutPosition(),view); 
       return true; 
      } 
     }); 

    } 

} 

public interface RecyclerItemClickListener{ 

    void onClickListener(SongInfoModel songInfoModel, int position); 
    void onLongClickListener(SongInfoModel songInfoModel, int position, View view); 

+0

대신에 ClickListener에 열려 새로운 활동의 조각을 대체하는 단편 트랜잭션을 확인합니다. – Aiapaec

+0

코드 예제를 들어 주시겠습니까? – Rektirino

+0

MyFilesSongs 클래스를 조각으로 변경하고 기존 조각을 Adpater 클래스의 새 조각으로 바꿉니다. –

답변

0

첫째, 활동에 그 모두 recyclerviews 호스트이를 추가해야합니다 :

<FrameLayout android:id="@+id/fragment_change" 
android:layout_width="match_parent" android:fitsSystemWindows="true" 
android:layout_height="match_parent"/> 

당신의 조각 모두 당신이 주요 컨테이너로 그와 함께 갈 단지 RecyclerViews 때문에, 활동에 (확인이이 AppCompatActi입니다 에이 확장이

SupportFragmentManager fragmentManager = getSupportFragmentManager(); 
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
FilesListFragment fragment = new FilesListFragment(); 
Bundle bundle = new Bundle(); 
bundle.putInt("parentPath",name.getFolderPath()); 
fragment.setArguments(bundle); 
fragmentTransaction.replace(R.id.fragment_change, fragment); 
fragmentTransaction.commit(); 

그리고 파일이있는 RecyclerView을 보유하고있는 활동

SupportFragmentManager fragmentManager = getSupportFragmentManager(); 
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
FolderListFragment fragment = new FolderListFragment(); 
fragment.setArguments(bundle); 
fragmentTransaction.replace(R.id.fragment_change, fragment); 
fragmentTransaction.commit(); 

을 그리고 foldersAdapter에서 대신 활동을 호출하는이 함께 가야한다 : vity),이 전화 파편. 조각의 한 OnCreate에

:

Bundle bundle = this.getArguments(); 
if (bundle != null) { 
     int myInt = bundle.getString("parentPath", defaultValue); 
} 
+0

실제로 MainActivity.java는 "MyFiles"조각을 호스트하고 Songs.java는 MainActivity와 같은 독립적 활동입니다. – Rektirino

+0

Songs.java가 액티비티 인 반면 MyFiles는 프래그먼트입니다. – Rektirino

+0

그리고 첫 번째 GIF에서 볼 수 있듯이 모든 프래그먼트가 뷰 페이지 (tablayout)에 있습니다. – Rektirino

0

솔루션으로 Expandable Recycler View를 사용하고 싶을 것입니다. 여기 링크입니다

Expandable RecyclerView

당신은, 확장 가능한 리사이클보기의 구현에 관한 문제가 해달라고하면 나는 희망이 도움이 도움이 될 것입니다 주저)

+0

아니요, 확장형 Recycler보기에서 수행하는 작업을 알고 있습니다. 내 질문 다시 읽기 – Rektirino

+0

오, 미안 메이트 참조;) 나는 괜찮아 내가 그걸 도울 수 있다면 단편을 구현 같은 활동에 오디오 목록 (또는 당신이 가지고있는 모델의 목록)을 보여 다른 조각을 사용할 수 있습니다 생각합니다. – Aliy

+0

문제는 없지만 조각을 도울 수 있습니까? – Rektirino