2013-01-07 16 views
0

的Xml我LargeText查看我如何刪除單個字符,如(') android系統

<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 它(?)一個瘋狂的一天。

我想知道這個錯誤的答案我試圖實現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 /消息(24930):風險因素:除了是女性,年齡增長是最重要的危險因素乳腺癌。潛在可改變的危險因素包括18歲以後的體重增加,超重或肥胖(絕經後乳腺癌),MHT(聯合雌激素和孕激素治療)的使用,缺乏身體活動和飲酒。預測高風險的醫學發現包括高乳房組織密度(乳腺組織相對於乳房脂肪組織的量的乳房X射線測量),高骨密度(低密度婦女骨質疏鬆症的風險增加)和活組織檢查 - 證實增生(細胞過度生長),特別是非典型增生(過度生長的細胞不正常)。胸部用於癌症治療的高劑量輻射也增加了風險。增加風險的生殖因素包括月經過去的歷史較長(月經期開始時間早或結束時間較晚),最近使用口服避孕藥,從未有孩子,並且有one?s 30歲以後的第一個孩子。

+0

請向我們展示設置文本的代碼。 – Henry

+1

試試這是一個瘋狂的日子 –

+0

我想我誤解了你的問題,你的問題是你的'正在被句子替換(?),我是否正確? –

回答

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捷克:捷克克魯姆
UTF-8日本:日本語
ISO-8859-1捷克:埃斯克
ISO-8859-1 japanese:???

ISO-8859-1是android的標準編碼。所以這就是爲什麼你可能會得到「?」字符,而不是適當的字符。

您需要將其更改爲UTF-8。
我想你可以弄清楚如何看看上面的例子。