【问题标题】:Change textview depending on time根据时间更改文本视图
【发布时间】:2016-08-17 01:51:17
【问题描述】:

我想根据日期和时间更改我的 TextView 内容,目前我有一个输出日期和时间的文本视图,我想要另一个文本视图来查看它,如果它大于 17:00 和日期是 24/04/2016 然后它将文本更改为已关闭。或者我可以使用我的文本视图查看的文本时钟吗?

// 显示当前日期和时间

TextView tv = (TextView) findViewById(R.id.textView4);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
    String currentDateandTime = sdf.format(new Date());
    tv.setText(currentDateandTime);

【问题讨论】:

    标签: android textview clock


    【解决方案1】:

    我认为你需要这个:

    txt1.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
    
                 // write the condition for second textview here
                 if(date.equals("24/04/2016") && time.equals("17:00"))
                 {
                        txt2.setText("closed");
                 }
    
                }
            });
    

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 1970-01-01
      相关资源
      最近更新 更多