2016-04-23 69 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