안드로이드

sdcard에서 파일 읽어와 리스트 뷰로 출력

by 운영자 posted Oct 17, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//리스트 뷰 정의 
ListView listview= (ListView) findViewById(android.R.id.list);
//해당 경로를 설정하여 파일배열에 입력
File[] listFiles =(new File("/sdcard/camera/image").listFiles());
 
//넣어준 스트링을 리스트에 추가 해 줍니다.
List<String> listarray = new ArrayList<String>();
for( File file : listFiles )
listarray.add(file.getName());
//리스트에 뿌려줌
//셀력트는 임의 설정
ArrayAdapter<String> fileLists = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
//아답터에 셋팅
listview.setAdapter(fileList);