Android 如何在与EditText交互时打开弹出窗口?

Android 如何在与EditText交互时打开弹出窗口?,android,popupwindow,Android,Popupwindow,我希望在用户打开EditText进行编辑时打开一个弹出窗口。这是我的基本代码 toDate.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // TODO Auto-generated method stub

我希望在用户打开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进行编辑是什么意思?如果您的意思是当EditText变为“活动”时应执行操作,则您可能需要:


希望这有帮助

这正是我的意思。谢谢。如果答案解决了您的问题,请不要忘记将其标记为正确;-)