2013-04-02 133 views
0

我正在研究這個計算出租車票價的android項目。它有一個按鈕calculate,和一個菜單選項night-mode。這種方法確定兩點之間的距離,以及與之相關的出租車費用。按鈕點擊檢測

night-mode根據我們在這裏工作的夜車計算出租車費用。 night-mode的基本要求是它只能在當且僅當calculate進入onClick事件/如果方法被執行時才能運行。

在我的菜單選項...我怎麼檢查按鈕是真的點擊/或onClick事件被觸發?

回答

0

使其從你的計算法的OnClick後改變的狀態變量,並檢查是否您的變量有一個特定值,當夜間模式被點擊(既作爲按鈕版本)

例如:

int integer=0; 

    public void onClick(View v) { 
      if (v == calculate){ 
        if (integer == 0) 
          integer =1; //this makes your integer variable 1 if calculate is pressed the first time 

        else if (integer == 1) 
          integer=0;//this makes your integer variable 0 if calculate is pressed the second time(at the end of the drive) 
    //do calculate things 
    } 
    else if (v == nightmode){ 
      if(integer == 1){ 
      //do nightmode things 
      } 
      else{} 
    }