2016-04-23 70 views
0

我想改变我的TextView内容取决于日期&时间,目前我有一个文本视图输出日期和时间,我想另一个文本视图来看看它,如果它大于17 :00和日期是2016年4月24日,然后它将文本更改为关闭。或者我可以使用我的textview看起来的文本时钟?根据时间改变textview

//显示当前日期和时间

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

回答

0

我认为你需要这样的:

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

      } 
     }); 
+0

完美的答案欢呼 – james