"\ n"

2012-12-25 2 views
0

에서 결과 행을 분할 할 때 안드로이드에서 호출 로그를 얻는 중 안드로이드에서 호출 로그를 검색하는 동안 "\ n"에 대한 결과를 나눌 때 인덱스를 벗어납니다. 색인 1에 대한 투영" n"

/* 
    * projection string that will contain the values retrieved 
    */ 
    String[] projection = new String[] { Calls.DATE, Calls.NUMBER, Calls.DURATION }; 

    /* 
    * Cursor to loop on the results of the query 
    */ 
    Cursor callLogCursor = getApplicationContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, projection, null, null, CallLog.Calls.DEFAULT_SORT_ORDER); 

    callLogCursor.moveToFirst(); 

    /* 
    * Loop through the call log and get the number needed or until 
    * we retrieved all call logs 
    */ 
    String row; 
    while (callLogCursor.isAfterLast() == false) { 
     for (int i=0; i<callLogCursor.getColumnCount(); i++) { 
      row = callLogCursor.getString(i); 
      String[] parts = row.split("\n"); 
      showToast(callLogCursor.getString(i)); 
      callLogs += CommonUtils.formatDate(parts[0]) + "-" + parts[1] + "-" + parts[2] + "\n"; 
     } 
      numberOfCallLogRetrieved++; 
      callLogCursor.moveToNext(); 
    } 

여기에 뭔가 빠졌는지 확실하지 않습니다. 나는 정말 어떤 도움을 주셔서 감사합니다.

토스트 3 개 값을 연속적으로

감사

+0

처럼 보이는'showToast (callLogCursor.getString (I))으로 이동하십시오;은'split' 호출 이상에 '라인을, 우리에게 실제 스택 추적과 내용을 보여 건배 (또는, 선호, [안드로이드 로깅 시스템] (http://developer.android.com/tools/debugging/debugging-log.html)을 사용하여 우리 모두에게 그것을 보여줍니다. 아마도 이것은 스스로 디버깅하기에 충분합니다 –

+0

showToast는 실제로 toast.makeText (...). show()를 호출합니다. 매번 유효한 값을 가진 연속적인 3 개의 토스트를 표시합니다. – wassim

+0

만큼 생각했지만, 충돌했을 때 값을 볼 수 있기를 바랍니다. 그래서 우리는 문제를 도울 수 있습니다. 토스트 메시지에 있다면 질문을 편집하고 스택 추적과 함께 추가하십시오. 로거는 복사하여 붙여 넣기가 더 쉽습니다. –

답변

0

을 보여주는 사실은 혼자 결과를 개별 결과를 가져옵니다 루프에 대한 @Martin 발

에 대한 답변 덕분에 발견했다. 따라서 callLogCusor.getString (i)을 가져올 때 모든 행이 아닌 특정 열의 값을 얻고 있습니다.

코드는 이제

for (int i=0; i<callLogCursor.getColumnCount(); i++) { 
      if(i == 0){ 
       String type = getLogType(callLogCursor.getString(i)); 
       callLogs += type; 
      } else if (i == 1){ 
       callLogs += "-" + CommonUtils.formatDate(callLogCursor.getLong(i)); 
      } else if (i == 2){ 
       callLogs += "-" + callLogCursor.getString(i); 
      } else if (i == 3){ 
       callLogs += "-" + CommonUtils.formatDuration(callLogCursor.getInt(i)) + "\n"; 

      } 
     }