2013-03-08 109 views
-3

我在我的Android應用程序一名認爲,似乎呈現出某種內存引用,而不是說我已經將它設置爲顯示字符串資源。它看起來與當您嘗試使用java中的默認toString打印數組時發生的情況相同。任何幫助,試圖發現什麼是錯的將是一個很大的幫助。我會後下面的代碼片段:的Android TextView的顯示內存引用

XML佈局

<TextView 
    android:id="@+id/summary_name_heading" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="40dp" 
    android:layout_marginTop="20dp" 
    android:background="@color/secondary" 
    android:textColor="@color/text" 
    android:textSize="22sp" /> 

字符串資源

<string name="summary_name_heading_text">Song : </string> 

代碼

TextView nameHeading = (TextView)findViewById(R.id.summary_name_heading); 
nameHeading.setText(R.string.summary_name_heading_text); 

這是它在屏幕上顯示:

android.wi [email protected]

+0

粘貼在那裏你想顯示你的'TextView'文本中的代碼片段。 – SudoRahul 2013-03-08 14:30:50

+0

這些是代碼片段我只是填充從資源文件夾中我沒有​​Android的代碼處理的標題字符串這個文本視圖。 – peppermcknight 2013-03-08 14:33:00

+0

檢查我的答案。嘗試這樣做,它應該**顯示**你想要的。 – SudoRahul 2013-03-08 14:35:53

回答

0

你要傳遞給你要顯示你的TextView字符串的setText方法。如果你傳遞一個TextView的情況下,TextViewtoString()的方法將被調用。

0

不知道你在你的活動正在做的事情,但是這是你怎麼從你TextView獲取數據。

TextView tv = (TextView) findViewById(R.id.summary_name_heading); 
String myText = tv.getText(); 

myText現在有您想要的文字。

更新: -

在您的活動設置String

String mystring = getResources().getString(R.string.summary_name_heading_string); 
tv.setText(mystring); 

但儘管如此,作爲A-C建議,儘量清理項目,並修改字符串名稱和您TextViewId

+0

我不想從這個textview中檢索文本,因爲我自己在strings.xml中定義了它,我的問題是不是顯示這個字符串,而是顯示上面顯示的東西 – peppermcknight 2013-03-08 14:35:40