2

I am working on a sound recorder app. I have made the app so that it properly records mp3 files and saves them. Now I want to make it to be able to display the recordings and after they are clicked to start up a custom dialog in which the user can play the file, pause, or move the progress bar...

This is what I basically want to achieve here:

enter image description here

This is what I have at the moment:

enter image description here

I would like to populate the ListFragment with mp3 files from a specific directory. So basically list files from SDCard in ListFragment.

public class TwoFragment extends ListFragment implements       AdapterView.OnItemClickListener{

public TwoFragment() {
    // Required empty public constructor
}

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



}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_two, container, false);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.heroes, android.R.layout.simple_list_item_1);

    setListAdapter(adapter);
    getListView().setOnItemClickListener(this);
}

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l){

    Toast.makeText(getActivity(), "Item " + i, Toast.LENGTH_SHORT).show();
}

}

And this is the xml file for FragmentTwo

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

    <TextView
        android:id="@android:id/empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </TextView>

</LinearLayout>

I am kinda lost at the moment, I have tried googling, haven't really made any progress as I don't know how to properly "link"(?) the files from sdcard to display in ListView. I should probably do something with the Adapter but I'm not sure. Thanks for any help!

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
  • you have to create a separate class that `extends ArrayAdapter` and instead of `createFromResource` (because that is simply putting the values from `R.array.heroes`) you gonna use normal Java `new MyAdapter();`. Here is an answer showing an example adapter http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view – Budius Feb 24 '16 at 15:11
  • I have trouble making it work because I use ListFragment and whatnot, unlike in that example. Still struggling... – kapatikojoces Feb 24 '16 at 19:08
  • I don't understand your issue. The linked example is showing how to create a custom adapter. You'll replace the custom adapter on your code on the line `setListAdapter(adapter);` – Budius Feb 24 '16 at 21:58
  • I've added this code http://stackoverflow.com/a/33774046/4690795 and I get this http://i.imgur.com/bQp8qMz.jpg, which error I do understand but don't know how to fix since it a fragment not an activity (I suppose? idk) sorry i'm new to android in general – kapatikojoces Feb 25 '16 at 11:53

0 Answers0