Dans votre présentation , vous aurez besoin de quelque chose pour afficher le texte. Un TextView
est le choix évident. De sorte que vous aurez quelque chose comme ceci:
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Et votre code devrait ressembler à ceci:
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard,"file.txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.text_view);
//Set the text
tv.setText(text);
Cela pourrait aller dans l' onCreate()
méthode de Activity
, ou quelque part d'autre en fonction de ce qu'il est que vous voulez faire.