0

我想使用日历显示当前日期和时间。我的代码是

    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);

但它显示该应用程序不幸停止工作而不显示日期..

4

1 回答 1

1

为每个视图设置布局参数将解决您的问题

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
于 2013-01-17T16:01:34.053 回答