0

XML

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffb6c1" >
             <TextView
                 android:id="@+id/def"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentBottom="true"
                 android:layout_centerHorizontal="true"
                 android:background="@android:color/white"
                 android:textAppearance="?android:attr/textAppearanceLarge"
                 android:textSize="24dp" />           
    </RelativeLayout>
</ScrollView>

File.txtたとえば、次のような文があります。

文=(今日はクレイジーな日です)。

View に出力する LargeText It(?) クレイジーな日です。

クラスを実装しようとしたこのエラーの答えを知りたいのStringBuilderですが、Androidで機能させる方法がわかりません。

これは私が行ったすべての変更ですが、まだ成功していません。

package org.health.canser;

public void onCreate(Bundle savedInstanceState)
{
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
             //setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.breast);
    getFile(breastFile);

}

//my text fiel input section===============================================================================
public String loadTextFile(InputStream inputStream) throws IOException {
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    byte[] bytes = new byte[4096];
    int len = 0;
    while ((len = inputStream.read(bytes)) > 0)
    byteStream.write(bytes, 0, len);
    //return new String(byteStream.toByteArray(), "UTF8");
    return new String(byteStream.toByteArray(), "UTF-8");
    }

public void getFile(String fileName)
{


     breast= (View) findViewById(R.id.breastDef);
    AssetManager assetManager = getAssets();
    InputStream inputStream = null;
    try {
    inputStream = assetManager.open(fileName);
    String text = loadTextFile(inputStream);
    Log.i("Msg","msg: " + text);
         ((TextView) breast).setText(text);



    } catch (IOException e) {
    ((TextView) breast).setText("Couldn't load file");
    } finally { 
    if (inputStream != null)
    try {
    inputStream.close();
    } catch (IOException e) {
    ((TextView) breast).setText("Couldn't close file");
    }
    }


}

}

出力:

01-07 15:03:53.628: I/Msg(24930): 危険因子: 女性であることに加えて、加齢は乳がんの最も重要な危険因子です。潜在的に修正可能な危険因子には、18 歳以降の体重増加、過体重または肥満 (閉経後の乳がんの場合)、MHT (エストロゲンとプロゲスチンの併用ホルモン療法) の使用、運動不足、およびアルコール消費が含まれます。より高いリスクを予測する医学的所見には、高い乳房組織密度(乳房の脂肪組織に対する腺組織の量のマンモグラフィ測定値)、高い骨ミネラル密度(密度が低い女性は骨粗しょう症のリスクが高い)、生検などがあります。過形成(細胞の過剰増殖)、特に非定型過形成(正常に見えない細胞の過剰増殖)が確認されました。がん治療のための胸部への高線量放射線もリスクを高めます。30歳以降の最初の子供。

4

1 に答える 1

1

これはおそらく直接的な答えではありませんが、大いに役立つはずです:

package test;

public class Test {

    public static void main(String... args) throws Exception {
        String czech = "Český";
        String japanese = "日本語";

        System.out.println("UTF-8 czech: " + new String(czech.getBytes("UTF-8")));
        System.out.println("UTF-8 japanese: " + new String(japanese.getBytes("UTF-8")));

        System.out.println("ISO-8859-1 czech: " + new String(czech.getBytes("ISO-8859-1")));
        System.out.println("ISO-8859-1 japanese: " + new String(japanese.getBytes("ISO-8859-1")));
    }

}

UTF-8 チェコ語: Český
UTF-8 日本語: 日本語<br> ISO-8859-1 チェコ語: ?esk�<br> ISO-8859-1 日本語: ???

ISO-8859-1 は、Android の標準エンコードです。そのため、おそらく「?」が表示されます。適切な文字ではなく、文字。

これを UTF-8 に変更する必要があります。
上記の例を見ていただければわかると思います。

于 2013-01-07T13:42:14.710 に答える