Creating Android Notepad App: 4. Making list of created Text files on External Storage using ListView

In this part we are going to see, how we can generate list of files which we have created on external storage and how we can show that list in ListView.
So lets see….


Topics Covered

i. Overview on Custom Interface of ListView

As you seen in the first part, how we have created interface to show file list in ListVIew. Now its time to show some actual content in ListView. But before that lets take an overview on Custom list item and what will come where.

Making list of created Text files on External Storage using ListView

listview_item.xml

ii. Creating new Object type to hold File Information

Before creating Custom ListView Adapter, we need to create an Object type to hold File information like File Name and the short text of text file to show on ListView Item. So we can identify the file names and also we can get brief idea what is the text is containing in the file.
So let’s create a new Object type. Create a new java file named FileName.java. Define the constructor with two parameters, one is name as a String for file name and another is shorttext as a String for short text of text file. See the code below.


Now define getter and setter methods to get and set the File Name and Short Text. See the code below.

Complete FileName.java Class will looks like below.

iii. Working with Custom ListView Adapter

To provied the data to the each item of the listview and display it on item too, we need to make a bridge for it. i.e. Adapter for ListView. In this case we have to make custom adapter for our custom listview and to make it we will use ArrayAdapter class as base class to create custom adapter.
See the code below how the custom adapter class is illustrated.

iv. View the List of all Files in ListView

Now it’s time to generate file name list from the location where we have saved our files. Open the NoteManager.java and create a public function GetNotesList() and set return type ArrayList. See the code below.

Now open Main.java and get the list of files in array. Once you get all the files array. Define a new adapter and set it to ListView in Main.java inside the onCreate() function. Run the project and see the result. Creating Notepad Application in Android

Creating Android Notepad App

Donwload Gradle Source

4 replies
    • Ajay Bagujar
      Ajay Bagujar says:

      Thanks Danneelitz,
      Once I will get it done for Lollipop, I will update you. In between you can download the source from my blog and make few necessary modifications for lollipop.

      Reply
  1. faiz
    faiz says:

    String desc = new NoteManager().readNote(file[i].getName());

    i am getting an error on .readNote (cannot resolve symbol)
    where do you define that ?

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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