Sort data coming from phone storage in alphabetical format?

Home / Uncategorized / Sort data coming from phone storage in alphabetical format?

I am beginner in android.I am trying to get audio files from storage and put it in recycler view.And it loads perfectly but,i don’t know how do i sort that whole list in alphabetical order of that file name.I have tried some ways but it did not worked. Please help me to solve this.Thank you.

This is My Java file: class Recycler_MusicPlayer extends Recycler_Music_Player_onclick {
// private RecyclerView recyclerView;
Adapter adapter;
Cursor musiccursor;
int music_column_index;
int count;
FastScrollRecyclerView recyclerView;

protected void onCreate(Bundle savedInstanceState) {
setTitle("List of Songs");
recyclerView = (FastScrollRecyclerView) findViewById(;
recyclerView.setLayoutManager(new LinearLayoutManager(this));

String[] proj = {MediaStore.Audio.Media._ID,
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
count = musiccursor.getCount();
adapter = new Adapter(this);


public class Adapter extends RecyclerView.Adapter {

private Context mContext;
private LayoutInflater inflater;

public Adapter(Recycler_MusicPlayer recycler_musicPlayer) {
inflater = LayoutInflater.from(recycler_musicPlayer);
mContext = recycler_musicPlayer;

public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.song_layout, parent, false);
return new MyViewHolder(view);


public void onBindViewHolder(MyViewHolder holder, int position) {
String id = null;
music_column_index = musiccursor
id = musiccursor.getString(music_column_index);
music_column_index = musiccursor
id += " Size(KB):" + musiccursor.getString(music_column_index);;

public int getItemCount() {
return count;

public class MyViewHolder extends RecyclerView.ViewHolder {
TextView song;
ImageView play;

public MyViewHolder(View itemView) {
song = (TextView) itemView.findViewById(;
play = (ImageView) itemView.findViewById(;
itemView.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
if (mMediaPlayer.isPlaying()) {
Log.e("zzzzzzzzzzzz", "is playingggg");
pause = 0;
Log.e("ddddddddddd", "after set play on click");
int pos = getAdapterPosition();
startActivity(new Intent(v.getContext(), Recycler_Music_Player_onclick.class)
.putExtra("pos", pos));



You need to sort record in manage query try below changes

You can manage order by ascending descending order

Ascending order
String sortOrder = MediaStore.Audio.Media.DISPLAY_NAME+ " ASC";
Descending order
String sortOrder = MediaStore.Audio.Media.DISPLAY_NAME+ " DESC";
Change in manage query
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj, null, null, sortOrder);
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *