2013-05-27 47 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

相关问题