该应用程序应该有两个按钮和一个TextView,一个用于日期和另一个用于时间。点击日期按钮会在TextView中为您提供当前日期,并为时间按钮提供相同的日期。 updateTime类是我遇到问题的地方。我尝试了将该日期传递给ID的不同方式。Android:我无法将日期传递给我的字符串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”。 – 2012-02-16 07:02:07
认真地,您需要先学习如何在java中进行编码。该代码是一个完整和彻底的混乱。 – mbh 2012-02-16 07:06:25