问题是我不知道如何将这些构建在一起(代码示例)。我是 Android 编程新手,不知道如何从文本文件中读取并与输入字符串进行比较。现在我到目前为止:
@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());
} }