Android實現自訂時鐘控制項

來源:互聯網
上載者:User

現在這個DEMO把它封裝成自訂控制項,對外僅提供了3個公用介面:

1    public void switchClockState(_ClockState state)                        // 切換時鐘狀態
2                
3                public void saveTimeToSystem()                                                // 儲存錶盤時間到系統時間
4                
5                public void reviseTime()                                                                // 恢複目前時間為系統時間
那麼在使用起來就相對方便了 看看主Activity裡的代碼,是不是很簡單:
01    public class CustomClockDemoActivity extends Activity {
02        /** Called when the activity is first created. */
03        private CustomClock                mCustomClock1;
04        private CustomClock                mCustomClock2;
05        private CustomClock                mCustomClock3;
06        private Button                         mBtnSetting;
07        private Button                         mBtnSave;
08        private Button                         mBtnNoSave;
09    
10        public void onCreate(Bundle savedInstanceState) {
11        super.onCreate(savedInstanceState);
12        setContentView(R.layout.main);
13        init();
14        }
15            
16        public void init(){
17        mCustomClock1 = (CustomClock) findViewById(R.id.clock1);
18        mCustomClock1.switchClockState(CustomClock._ClockState.eQ_CLOCK_RUN);
19        mCustomClock2 = (CustomClock) findViewById(R.id.clock2);
20        mCustomClock2.switchClockState(CustomClock._ClockState.eQ_CLOCK_RUN);
21        mCustomClock3 = (CustomClock) findViewById(R.id.clock3);
22        mCustomClock3.switchClockState(CustomClock._ClockState.eQ_CLOCK_RUN);
23        mBtnSetting = (Button) findViewById(R.id.buttonSetting);
24        mBtnSetting.setOnClickListener(new OnClickListener() {
25    
26        @Override
27        public void onClick(View v) {
28        // TODO Auto-generated method stub
29        Setting();
30        }
31        });
32    
33        mBtnSave = (Button) findViewById(R.id.buttonSave);
34        mBtnSave.setOnClickListener(new OnClickListener() {
35    
36        @Override
37        public void onClick(View v) {
38        // TODO Auto-generated method stub
39        Save();
40        }
41        });
42        mBtnNoSave = (Button) findViewById(R.id.buttonNoSave);
43        mBtnNoSave.setOnClickListener(new OnClickListener() {
44    
45        @Override
46        public void onClick(View v) {
47        // TODO Auto-generated method stub
48        noSave();
49        }
50        });
51        mCustomClock1.setVisibility(View.INVISIBLE);
52        mCustomClock2.setVisibility(View.GONE);
53        mCustomClock3.setVisibility(View.GONE);
54    
55        }
56    
57        public void Setting(){
58    
59        mCustomClock1.switchClockState(CustomClock._ClockState.eQ_CLOCK_SETTING);
60        }
61    
62        public void Save(){
63    
64        mCustomClock1.saveTimeToSystem();
65        mCustomClock1.switchClockState(CustomClock._ClockState.eQ_CLOCK_RUN);
66        }
67    
68        public void noSave(){
69        mCustomClock1.reviseTime();
70        mCustomClock1.switchClockState(CustomClock._ClockState.eQ_CLOCK_RUN);
71        }
72    
73        }

Android相關內容:

  • android怎麼在radiobutton旁邊添加view
  • Android如何擷取MD5 certification key
  • Android如何給電子郵件內容添加新的一行
  • android中的預設表徵圖在哪個路徑下能找到
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.