0

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

残念ながら、日付を表示せずにアプリが動作しなくなったことを示しています..

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 に答える