2017-01-01 4 views
0

나는 안드로이드 SMS 애플 리케이션에서 일하고있다. 그 중 일부는받은 편지함 데이터 (주소, 날짜, 본문) 및 채우기 목록보기를 가져와야합니다. 이것은 다음과 같은 코드를 통해 잘 작동 :안드로이드 SMS 날짜 함수 호출

public void btnInboxOnClick { 

      // Create Inbox box URI 
      Uri inboxURI = Uri.parse("content://sms/inbox"); 

      // List required columns 
      String[] reqCols = new String[] { "_id", "address", "body", "date" }; 

      // Get Content Resolver object, which will deal with Content 
      // Provider 
      ContentResolver cr = getContentResolver(); 

      // Fetch Inbox SMS Message from Built-in Content Provider 
      Cursor c = cr.query(inboxURI, reqCols, null, null, null); 

      // Attached Cursor with adapter and display in listview 
      adapter = new SimpleCursorAdapter(this, R.layout.row, c, 
        new String[] { "body", "address", "date" }, new int[] { 
          R.id.lblMsg, R.id.lblNumber, R.id.lblDate }); 
      lvMsg.setAdapter(adapter); 

내가 밀리 번호가 DB에서 가져온 대신 의미있는 날짜 - 시간 문자열을 표시하는 함수 호출을 삽입 할. 내 기능 코드 :

public static String millisToDate(String TimeMillis) { 
     String finalDate; 
     long tm = Long.parseLong(TimeMillis); 
     Calendar calendar = Calendar.getInstance(); 
     calendar.setTimeInMillis(tm); 
     Date date = calendar.getTime(); 
     SimpleDateFormat outputFormat = new SimpleDateFormat("MMM-dd-yyyy HH:mm"); 
     finalDate = outputFormat.format(date); 
     return finalDate; 
    } 

함수를 컴파일하려고 시도했지만 응용 프로그램이 충돌합니다. 어떻게 함수를 연결해야합니까?

답변

0

감사합니다. 나 혼자서 해냈습니다.)이 answer도 도움이되었습니다. 감사합니다.

코드는 다음과 같습니다 :이 사람에게 도움이 될 것입니다

public void btnInboxOnClick { 

     // Create Inbox box URI 
     Uri inboxURI = Uri.parse("content://sms/inbox"); 

     // List required columns 
     String[] reqCols = new String[] { "_id", "address", "body", "date" }; 

     // Get Content Resolver object, which will deal with Content 
     // Provider 
     ContentResolver cr = getContentResolver(); 

     // Fetch Inbox SMS Message from Built-in Content Provider 
     Cursor c = cr.query(inboxURI, reqCols, null, null, null); 

     // Attached Cursor with adapter and display in listview 
     adapter = new SimpleCursorAdapter(this, R.layout.row, c, 
       new String[] { "body", "address", "date" }, new int[] { 
         R.id.lblMsg, R.id.lblNumber, R.id.lblDate }); 

    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { 

    public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) { 

     if (aColumnIndex == aCursor.getColumnIndex("date")) { 
      String createDate = aCursor.getString(aColumnIndex); 
      TextView textView = (TextView) aView; 
      textView.setText(millisToDate(createDate)); 
      return true; 
      } 

    return false; 
    } 
    }); 

     lvMsg.setAdapter(adapter); 

public static String millisToDate(String TimeMillis) { 
     String finalDate; 
     long tm = Long.parseLong(TimeMillis); 
     Calendar calendar = Calendar.getInstance(); 
     calendar.setTimeInMillis(tm); 
     Date date = calendar.getTime(); 
     SimpleDateFormat outputFormat = new SimpleDateFormat("MMM-dd-yyyy HH:mm"); 
     finalDate = outputFormat.format(date); 
     return finalDate; 
    } 

희망.