如何在Android Studio中更改给定日期的文本视图?

如何在Android Studio中更改给定日期的文本视图?,android,textview,Android,Textview,我想创建一个事件,以便在我选择的某一天显示一条新消息。例如:在1月1日,我可能希望它说“你好”,然后在1月5日,文本变为“嘿”或其他我事先决定的消息,这些消息将出现在我选择的某一天。关于如何做到这一点,或者我可以在哪里找到正确的方向,有什么想法吗?我是在Eclipse中提出的。同样的事情也会在安卓系统中发生。而不是System.out.println();您可以使用textView.setText() 哦,这将打印以下内容 4 6 2017 8 fourth fourth of august

我想创建一个事件,以便在我选择的某一天显示一条新消息。例如:在1月1日,我可能希望它说“你好”,然后在1月5日,文本变为“嘿”或其他我事先决定的消息,这些消息将出现在我选择的某一天。关于如何做到这一点,或者我可以在哪里找到正确的方向,有什么想法吗?

我是在Eclipse中提出的。同样的事情也会在安卓系统中发生。而不是System.out.println();您可以使用textView.setText()

哦,这将打印以下内容

4
6
2017
8
fourth
fourth of august
针对ANDROID STUDIO代码更新

主要活动

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView = (TextView) findViewById(R.id.textView);

        GregorianCalendar cal = new GregorianCalendar();

        System.out.println(cal.get(Calendar.DATE)); //prints 4
        System.out.println(cal.get(Calendar.MONTH) + 1); //this starts at 0, not 1. Therefore, add 1
        System.out.println(cal.get(Calendar.YEAR)); //2017

        if ((cal.get(Calendar.DAY_OF_MONTH) + 0 == 4) && (cal.get(Calendar.MONTH) + 1 == 8)) { //Is it the fourth of the month of 2017?
            System.out.println("TODAY IS AN A DAY");
            textView.setText("Today is August Fourth");
        } else {
            System.out.println("ERROR");
            textView.setText("Today is NOT August Fourth");
        }

    }
}
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vzw.www.calendar.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:text="Hello World!"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

公共课检查日{

public static void main(String[] args) {
    // TODO Auto-generated method stub

    GregorianCalendar cal = new GregorianCalendar();

    System.out.println(cal.get(Calendar.DATE)); //prints 4
    System.out.println(cal.get(Calendar.MONTH) + 1); //this starts at 0, not 1. Therefore, add 1
    System.out.println(cal.get(Calendar.YEAR)); //2017

    if ((cal.get(Calendar.DAY_OF_MONTH) + 0 == 4) && (cal.get(Calendar.MONTH) + 1 == 8)) { //Is it the fourth of the month of 2017?
        System.out.println("TODAY IS AN A DAY");
    } else {
        System.out.println("ERROR");
    }

}

}

嗯……检查日期,然后显示一条消息?应该有365个案例,如果是闰年的话,应该有一个额外的案例。;)两件事。。。它说如果(cal.get(Calendar.DAY\u OF_MONTH)==4,我就不能使用行中的数字,我应该把这个代码放在哪里,这样它就可以在我的应用程序上显示为一行文本显示你的代码。复制并粘贴到你的开场白中。它仍然只在主要活动上显示“Hello World!”,而不是“今天是八月四日”好像我的代码应该可以工作……你的代码仍然有问题。我的代码今天显示的是8月4日。如果你的代码不工作,那么我今天显示的不是8月4日。因为这是另一个条件。所以是的,你的代码错了……在某个地方。我猜是你的textview的ID。@Droidv这就是你所指的吗打电话给?我感到困惑的是,我有所有这些信息,这些信息都很好,但如果我不能显示它们,它对我没有任何帮助。我想把这些信息放在home.xml下的布局中,但我现在只有文本视图,上面写着home和WELCOME。我想让它写上“今天是一天”下面是我从上面的代码中得到的,但是它在一个类中,所以我不能只插入一个类。你没有android方面的经验吗?
public static void main(String[] args) {
    // TODO Auto-generated method stub

    GregorianCalendar cal = new GregorianCalendar();

    System.out.println(cal.get(Calendar.DATE)); //prints 4
    System.out.println(cal.get(Calendar.MONTH) + 1); //this starts at 0, not 1. Therefore, add 1
    System.out.println(cal.get(Calendar.YEAR)); //2017

    if ((cal.get(Calendar.DAY_OF_MONTH) + 0 == 4) && (cal.get(Calendar.MONTH) + 1 == 8)) { //Is it the fourth of the month of 2017?
        System.out.println("TODAY IS AN A DAY");
    } else {
        System.out.println("ERROR");
    }

}