生のテキスト ファイルを扱う Android アプリをコーディングしています。私が気付いたのは、トグル ボタンを使用すると、テキスト ビューでファイルの実際のテキストの前に奇妙な文字が表示されることです。下の写真は、私が話しているキャラクターを示しています。これらのキャラクターはアプリの最終バージョンには表示されないため、これらのキャラクターを取り除く方法を知りたいです。問題が何であるかを知っている人はいますか?
トグル ボタンを処理するコードは次のとおりです。
ELswitch = (ToggleButton)findViewById(R.id.toggleButton1);
ELswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked==true)
{
InputStream iFile = getResources().openRawResource(R.raw.sunday_compline_latin);
System.out.println(R.raw.sunday_compline_english);
try {
text.setText(inputStreamToString(iFile));
text.setFocusable(false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
InputStream iFile = getResources().openRawResource(R.raw.sunday_compline_english);
try {
text.setText(inputStreamToString(iFile));
text.setFocusable(false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
コードは正常に実行され、これらの文字は元のファイルに表示されないため、テキスト ファイルを変更するものはないようです。さらに、トグル ボタンを使用しない同様のアクティビティがあり、これらの文字はこのインスタンスにのみ表示されます (トグル ボタンを使用)。コードに問題はありますか?誰か提案がありますか?
これが私のinputStreamToStringです:
public String inputStreamToString(InputStream is) throws IOException
{
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = null;
while ((strLine = dataIO.readLine()) != null)
{
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
}
}