title: How to read a selected text file from sdcard on android
body: <p>i am new at android development and i need your help. I was locking at topics that are similar for my development but non of then help me.
  So far i create functions that gets me the files from my sdcard and shows me the list of then.
  That is working</p>
  
  <p>this is the code for getting the paths on sdcard:</p>
  
  <pre><code>package com.seminarskirad;
  
  import android.app.AlertDialog;
  import android.app.AlertDialog.Builder;
  import android.app.ListActivity;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.Environment;
  import android.provider.MediaStore;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.FilenameFilter;
  import java.io.IOException;
  import java.net.URISyntaxException;
  import java.util.ArrayList;
  import java.util.List;
  
  public class LoadActivity extends ListActivity{
  
       private enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
       private final DISPLAYMODE displayMode = DISPLAYMODE.ABSOLUTE;
       private List&lt;String&gt; directoryEntries = new ArrayList&lt;String&gt;();
       private File currentDirectory = new File("/");
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              Browse(Environment.getExternalStorageDirectory());
  
          }
  
          private void upOneLevel(){
                  if(this.currentDirectory.getParent() != null)
                          this.Browse(this.currentDirectory.getParentFile());
          }
  
          private void Browse(final File aDirectory){
                  if (aDirectory.isDirectory()){
                          this.currentDirectory = aDirectory;
                          fill(aDirectory.listFiles());
  
                }
          }
  
          private void fill(File[] files) {
                  this.directoryEntries.clear();
                  if(this.currentDirectory.getParent() != null)
                          this.directoryEntries.add("..");
  
                  switch(this.displayMode){
                          case ABSOLUTE:
                                  for (File file : files){
                                          this.directoryEntries.add(file.getPath());
                                  }
                                  break;
                          case RELATIVE: // On relative Mode, we have to add the current-path to the beginning
                                  int currentPathStringLenght = this.currentDirectory.getAbsolutePath().length();
                                  for (File file : files){
                                          this.directoryEntries.add(file.getAbsolutePath().substring(currentPathStringLenght));
                                  }
                                  break;
                  }
  
          ArrayAdapter&lt;String&gt; directoryList = new ArrayAdapter&lt;String&gt;(this, R.layout.load, this.directoryEntries);
          this.setListAdapter(directoryList);
          }
  
          protected void onListItemClick(ListView l, View v, int position, long id) {
                  int selectionRowID = position;
                  String selectedFileString = this.directoryEntries.get(selectionRowID);
                  if(selectedFileString.equals("..")){
                          this.upOneLevel();
                  }else if(selectedFileString.equals()){   /// what to write here ???
                          this.readFile();    ///what to write here???
                  } else {
                          File clickedFile = null;
                          switch(this.displayMode){
                                  case RELATIVE:
                                          clickedFile = new File(this.currentDirectory.getAbsolutePath()
                                                                                                  + this.directoryEntries.get(selectionRowID));
                                          break;
                                  case ABSOLUTE:
                                          clickedFile = new File(this.directoryEntries.get(selectionRowID));
                                          break;
                          }
                          if(clickedFile.isFile())
                              this.Browse(clickedFile);
                  }
          }
  
          private void readFile() {
  // what to write here???
          }
  </code></pre>
  
  <p>Sorry i cant put the image because i dont have reputation, but when i run it on my emulator a get something like this:</p>
  
  <pre><code> /mnt/sdcard/kuzmanic.c
  /mnt/sdcard/text.txt
  /mnt/sdcard/DCIM
  /mnt/sdcard/LOST.DIR
  </code></pre>
  
  <p>So what I want to do is when i click on the text.txt or kuzmanic.c file I want to open then in the same layout file, that is my load.xml file:</p>
  
  <pre><code>This is the code for the xml file:
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" 
      android:textSize="18sp"&gt;    
  
  
  &lt;/TextView&gt;
  </code></pre>
  
  <p>What i need to write in my code and do I have to write anything in the manifest???</p>