2013-04-18 1 views
0

다음 코드를 사용하여 Share 메뉴를 통해 다른 응용 프로그램에서 내 응용 프로그램으로 TEXT를 보내고 EditText에 TEXT를 표시합니다.공유 메뉴를 통해 전송 된 텍스트 문자열 서식 지정 방법

Intent receivedIntent = getIntent();  
    String receivedAction = receivedIntent.getAction();  
    String receivedType = receivedIntent.getType(); 
    TextView txtView = (EditText) findViewById(R.id.edWord); 
    //if(receivedAction.equals(Intent.ACTION_SEND)){ 
    if (Intent.ACTION_SEND.equals(receivedAction) && receivedType != null) { 
     if(receivedType.startsWith("text/")) {          
      String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT).toLowerCase(); 
      if (receivedText != null) 
      {     
       txtView.setText(receivedText); 
       txtView.requestFocus(); 
       ListView myList=(ListView) findViewById(R.id.lstWord); 
       myList.setFocusableInTouchMode(true); 
       myList.setSelection(0); 
      } 
      else 
       txtView.setText(""); 
     } 
    } 

모든 즉, 잘 작동, 전송 된 텍스트는 내 글고 치기 (위의 코드에서, 즉 edWord)에 표시됩니다. 그러나 Share를 통해 전송 된 텍스트는 때때로 의미가없는 요소 또는 파생물로 구성됩니다 (예 : "word, word', word, 또는 looked, books, tomatoes).

내가 원하는 것은 EditText에 추가되기 전에 실제 단어 또는 기본 단어 형식 만 포함하도록 텍스트 서식을 지정하는 것입니다.

나는 approximate string matching 또는 fuzzy searching에 대해 들었지만 내 코드에 어떻게 적용 할 것인지 잘 모릅니다. 나는 적어도 위의 문제를 해결하기 위해 당신이 나에게 약간의 도움을 줄 수 있을지 궁금해한다.

미리 감사드립니다.

답변

0

제 질문의 첫 번째 부분에 대한 답변을 찾았습니다. 즉, 문자열에서 단어가 아닌 요소를 제거하는 것입니다 (시작 및/또는 문자열 종료). 여기 내가 사용하는 정규식 알고리즘의 비트와 코드입니다 :

String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT); 
      if (receivedText != null)     
      {     
       receivedText = receivedText.toLowerCase(); 

       //Remove all non-word elements starting and/or ending a string 
       String strippedInput = receivedText.replaceAll("^\\W+|\\W+$", ""); 
       System.out.println("Stripped string: " + strippedInput); 

       txtView.setText(strippedInput); 
       txtView.requestFocus(); 
       ListView myList=(ListView) findViewById(R.id.lstWord); 
       myList.setFocusableInTouchMode(true); 
       myList.setSelection(0); 
      } 

을 퍼지 검색에 대한 내 질문의 두 번째 부분을 들어, 나는 그것이 더 많거나 적은을위한 재 코딩하는 방법을 내 응용 프로그램 검색을 포함 추측 SQLlite 데이터베이스 결과. 이것은 여전히 ​​내 대답없는 질문입니다.