我想使用calendar.my代码
显示当前日期和时间 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);
但它显示应用程序不幸停止工作而不显示日期..
答案 0 :(得分: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