2013-08-14 2 views
0

72000 라인과 2,6M 크기의 파일이 있습니다. 이 파일에는 AutoCompleteTextView의 모든 문자열 항목이 있습니다. 현재 내가 같이 읽을 : 내가 활동을 시작할 때안드로이드에서 AutoCompleteTextView를위한 큰 목록 읽기

List<IcdObject> codes = new ArrayList<IcdObject>(); 
try { 
    InputStream input = getAssets().open("icd.txt"); 
    BufferedReader br = new BufferedReader(new InputStreamReader(input)); 

    String line; 
    while ((line = br.readLine()) != null) { 
    String[] icd = line.split("|"); 
    codes.add(new IcdObject(icd[0], icd[1])); 
    } 

    input.close(); 
} catch (IOException e) { 
    // TODO 
    e.printStackTrace(); 
} 
ArrayAdapter<IcdObject> adapter = new ArrayAdapter<IcdObject>(this, 
    android.R.layout.select_dialog_item, codes); 
AutoCompleteTextView at = (AutoCompleteTextView) findViewById(R.id.AutoComplete); 
at.setThreshold(3); 
at.setAdapter(adapter); 

가비지 컬렉터 미친 간다. 그러나 결국 1 분 정도 기다린 후에 모든 항목이로드됩니다. 필요에 따라 파일을로드하거나 빠르게로드 할 수있는 방법이 있습니까?

+1

대용량 파일을 완전히 구문 분석하고 메모리에있는 모든 항목을로드하는 것보다 훨씬 효율적이고 빠르지 만 검색 제안을 사용하여 데이터베이스를 미리 채우는 것이 좋습니다. 또한 UI 스레드에서 '필터링'프로세스를 이동하는 것이 더 합리적입니다. 'ArrayAdapter'는 그 목적을 위해서 오버라이드 할 수있는'getFilter()'메소드를 가지고 있습니다. 데이터베이스 경로를 내려 가기로 결정했다면,'CursorAdapter'에서'runQueryOnBackgroundThread()'메소드를 찾으십시오. –

답변