2013-04-01 95 views
0

我的textview顯示爲空白!甚至當我把一個字符串,它顯示blank..Please告訴我該怎麼做Textview沒有顯示任何內容

protected void OnCreate (Bundle savedInstanceState) throws ClientProtocolException, IOException, JSONException{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    TextView result = (TextView) findViewById(R.id.text1); 
    result.setText("TESTING"); 

這是我的XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 



</RelativeLayout> 
+1

刪除拋擲的onCreate異常,然後檢查。 –

+0

我試了..still什麼也沒有 – CanucksGirl

+0

其工作正常,但如果它的問題與你的代碼,那麼請把你的完整代碼在這裏.. – Ajay

回答

2

我已創建了一個程序與您的代碼,它在這裏工作很好...

我剛纔在下面4行中刪除:

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
0

你可能要檢查的RelativeLayout的填充性能。嘗試註釋掉所有填充屬性並檢查。

+0

我did..again沒有運氣.. – CanucksGirl

+0

老兄如何答案標記正確告訴任何不同於什麼這個答案說? –

0

嘗試增加的位置屬性的TextView的,例如設置它的alignParentTop =「真」

+0

我試過..沒有什麼:(( – CanucksGirl

+0

請確保你引用了正確的佈局文件activity_main –

0

刪除填充和再檢查。似乎沒有任何其他因素阻止文本顯示。

0

只需更換這對其做..

 @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

      TextView result = (TextView) findViewById(R.id.text1); 
      result.setText("TESTING"); 

     } 


     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context=".MainActivity" > 

     <TextView 
      android:id="@+id/text1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/hello_world" /> 

</RelativeLayout> 
+0

悲哀..仍然相同 – CanucksGirl

+0

爲什麼你在類中拋出ClientProtocolException?只是簡單的嘗試。 – pradip

0

更改文字顏色。

在XML中,

android:textColor="#FF0000" 

否則在Java中

myTextView.setTextColor(0xAARRGGBB);