2013-05-27 48 views
0

我想要一個彈出窗口在用戶打開EditText進行編輯時打開。這是我的基本代碼。如何在與EditText進行交互時打開彈出窗口?

toDate.setOnEditorActionListener(new OnEditorActionListener() { 

     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      // TODO Auto-generated method stub 

      initiatePopupWindow(); 
      return false; 
     } 
    }); 
} 


protected void initiatePopupWindow() { 
    // TODO Auto-generated method stub 

    try { 
     popDate = (LayoutInflater) TripData.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = popDate.inflate(R.layout.popdate, (ViewGroup) findViewById(R.id.popup)); 

     datePw = new PopupWindow(layout, 300, 370, true); 
     datePw.showAtLocation(layout, Gravity.CENTER, 0, 0); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

toDate是EditText。我知道問題是我沒有指定任何操作。我的問題是,我不知道如何指定操作。

回答

0

你是什麼意思「當用戶打開EditText進行編輯」?如果你的意思是,當EditText上變得「活躍」的動作應該執行,那麼你可能可能要:

setOnFocusChangeListener() reference page

希望這有助於

+0

這正是我的意思。謝謝。 –

+0

請不要忘記標記答案是正確的,如果它解決了你的問題;-) – Rick77

相關問題