1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public class FileActivity extends Activity{
Spinner spinner;
TextView file;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_main);
spinner = (Spinner) findViewById(R.id.SpinnerFiles);
file = (TextView) findViewById(R.id.textViewFile);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, fileList());
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
String fileName = (String) spinner.getSelectedItem();
if(fileName != null){
try{
InputStream inputStream = getResources().openRawResource(R.raw.reims);
if(inputStream != null){
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String str;
StringBuilder buf = new StringBuilder();
while ((str = reader.readLine()) != null){
buf.append(str+"\r\n");
}
reader.close();
inputStream.close();
file.setText(buf.toString());
}
}catch(java.io.FileNotFoundException e){
Toast.makeText(this, "FileNotFoundException", Toast.LENGTH_LONG);
}
catch(IOException e){
Toast.makeText(this, "FileNotFoundException", Toast.LENGTH_LONG);
}
}
}} |
Partager