Android日期和时间
我想使用日历显示当前日期和时间。我的代码是Android日期和时间,android,date,Android,Date,我想使用日历显示当前日期和时间。我的代码是 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 sec
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);
但它显示应用程序不幸停止工作而不显示日期。为每个视图设置布局参数将解决您的问题
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
当出现无法解决的错误或崩溃时,应该养成发布Logcat输出的习惯。