2013-01-17 69 views
0

我想用calendar.my代碼來顯示當前的日期和時間是Android的日期和時間

LinearLayout lview=new LinearLayout(this); 
    myText=new TextView(this); 
    strText=new TextView(this); 


    Calendar c=Calendar.getInstance(); 
    int seconds=c.get(Calendar.SECOND); 

    myText.setText("Your current seconds are:"); 
    strText.setText(seconds); 

    lview.addView(strText); 
    lview.addView(myText); 

    setContentView(lview); 

,但它顯示了應用程序不幸停止,不顯示日期的工作..

+2

您應該進入張貼logcat的輸出,當你有一個錯誤或崩潰,你解決不了的習慣。 – Karakuri

回答

1

設置佈局PARAMATERS爲每個視圖將解決你的問題

lview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));\\Linear Layout 
strText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); \\TextView 
myText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));\\TextView