2012-05-17 2 views
1

문제는 이것들을 함께 만드는 방법을 모르겠다. (코드 예). 안드로이드 프로그래밍에서 새로운 것인데, 어떻게 할 수 없는가? 과 비교하면 텍스트 파일에서 읽는다. 입력 문자열. 지금은이에 지금까지있어 : 당신이 "확인"으로 설정 한 후파일에서 문자열을 입력 문자열과 비교하는 방법은 무엇입니까? (안드로이드)

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Button btn = (Button) findViewById(R.id.bBtn); 
    final EditText input = (EditText) findViewById(R.id.edittext); 
    TextView display = (TextView) findViewById(R.id.tView); 

    parbaudesPoga.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View V) { 
      String check = input.getText().toString(); 
      if (check.contentEquals("word")) { 
       Toast.makeText(getApplication(), "True", 
         Toast.LENGTH_SHORT).show(); 

      } else { 
       Toast.makeText(getApplication(), 
         "False", Toast.LENGTH_SHORT) 
         .show(); 
      } 
     } 
    }); 
    InputStreamReader is = new InputStreamReader(this.getResources() 
      .openRawResource(R.raw.words)); 
    BufferedReader reader = new BufferedReader(is); 
    StringBuilder finalText = new StringBuilder(); 
    String line; 
    try { 
     while ((line = reader.readLine()) != null) { 
      finalText.append(line); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    display = (TextView) findViewById(R.id.bBtn); 
    display.setText(finalText.toString()); 

} }

+0

줄 또는 전체 파일을 한 번에 한 줄씩 비교 하시겠습니까? – techiServices

답변

0

음, 클릭 리스너에 비교하는 방법을 호출합니다. 인스턴스 변수를 "확인"하거나 메소드의 매개 변수로 전달할 수 있습니다.

이 메서드에서 파일을 읽고 텍스트 문자열이있는 즉시 비교하거나 다른 시점에서 읽은 다음 텍스트 문자열을 인스턴스 변수에 저장할 수 있습니다.

관련 문제