【发布时间】:2012-03-07 14:11:51
【问题描述】:
App 应该有两个 Button 和一个 TextView,一个用于日期,另一个用于时间。单击日期按钮将为您提供 TextView 中的当前日期,时间按钮也是如此。 updateTime 类是我遇到问题的地方。我尝试了不同的方法将该日期传递给 ID。
这是我的源代码和注释:
package com.CS211D.DateAndTime;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.Time;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.util.Date;
import java.util.Calendar;
import java.text.DateFormat;
/*
* This is the activity for my Android App that gives you the date and time when you click on a button. I'm having trouble trying to figure out the date syntax
*/
//*******************TimeAndDateActivity*******************
public class TimeAndDateActivity extends Activity implements View.OnClickListener
{
Button btn;
DateFormat fmtDateTime = DateFormat.getDateAndTimeInstance(); //other utils I've tried
Calendar mycal = Calendar.getInstance(); //with no avail
@Override
//*******************onCreate*******************
public void onCreate(Bundle b)
{
super.onCreate(b);
btn = (Button)this.findViewById(R.id.time); //Time Button
btn = (Button)this.findViewById(R.id.day); //Date Button
}
//*******************onClick*******************
public void onClick(View v) //Called when one of the buttons above is clicked is clicked
{
updateTime();
}
//*******************updateTime*******************
private void updateTime()
{
t = getTime()
btn.setText(getDate().toString(R.id.time));//Most of the methods I try eclipse says
//the method is either undefined or incompatible
//with the object
}
}
【问题讨论】:
-
这是什么...getDate().toString(R.id.time)???...你的意图是什么?并且您对两个按钮使用相同的引用“btn”..
-
说真的,你需要先学习如何用java编写代码。这段代码完全是一团糟。
标签: java android date time tostring