PopupWindow不长的EditText preSS触发系统正语境对话 [英] PopupWindow not triggering sytem context dialog on EditText long-press

查看:137
本文介绍了PopupWindow不长的EditText preSS触发系统正语境对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果标题是有点模糊。

我开发的自由职业者的应用程序,我几乎都只是从客户后,一些测试的投诉就完蛋了。

我用一个PopupWindow代替对话框编辑情景设置,如果让任何意义。我不想太具体和风险给应用程序的概念了,我敢肯定,客户不会太高兴。

该PopupWindow给出从XML充气布局中的内容的浏览。在这种布局有几个的EditText小部件。问题是,这些EditTexts不会触发长preSS是presents选择文本/输入法选择,剪切/复制/粘贴的默认上下文对话框。

我看到了类似的问题,试图让TouchTrigger或东西,它不工作没有setBackgroundDrawable(),我已经尝试用一个简单的新ColorDrawable()。它仍然无法正常工作。

有没有简单的方法来触发一个OnLong pressListener系统默认的长preSS对话框,否则我将不得不动天地,以实现它自己?因为如果是那样的话,我就写一个片段,并交换它在一个事务中。我知道这会工作。

相关code: 引发片段里面:

  RulesDialog对话框;
PopupWindow窗口;

公共无效showAddRuleDialog(){
    对话框=新RulesDialog();

    查看查看= getView();

    窗口=新PopupWindow(dialog.initViews(本,空),view.getWidth(),view.getHeight(),TRUE);

    window.setBackgroundDrawable(新ColorDrawable());

    dialog.setRulesDialogListener(新rulesDialogListener(){

        @覆盖
        公共无效的OnSave(ViewHolder持有者){


            addRule(保持器);

            window.dismiss();


        }

        @覆盖
        公共无效OnCancel的(){
            window.dismiss();

        }});

    INT []位置= {0,0};
    view.getLocationOnScreen(位置);



    window.showAtLocation(查看,0,位置[0],位置[1]);
 

在RulesDialog:

 公共类ViewHolder {
    公共ViewHolder(查看dialogView){
        名称=(TextView中)dialogView.findViewById(R.id.name);
        响应=(TextView中)dialogView.findViewById(R.id.response);

        发件人=(TextView中)dialogView.findViewById(R.id.senders);
        sendersAdd =(按钮)dialogView.findViewById(R.id.sendersAdd);
        sendersEdit =(按钮)dialogView.findViewById(R.id.sendersEdit);

        timeFrom =(TextView中)dialogView.findViewById(R.id.from);
        timeFromEdit =(按钮)dialogView.findViewById(R.id.timeBeforeEdit);
        timeTo =(TextView中)dialogView.findViewById(R.id.to);
        timeToEdit =(按钮)dialogView.findViewById(R.id.timeAfterEdit);

        关键字=(TextView中)dialogView.findViewById(R.id.keywords);

        matchCase =(复选框)dialogView.findViewById(R.id.matchCase);
        matchAlone =(复选框)dialogView.findViewById(R.id.matchAlone);
        matchPlural =(复选框)dialogView.findViewById(R.id.matchPlural);

        取消=(按钮)dialogView.findViewById(R.id.cancel);
        节省=(按钮)dialogView.findViewById(R.id.save);


    }

    TextView的名称;
    TextView的响应;
    TextView的发件人;
    按钮sendersAdd;
    按钮sendersEdit;
    TextView的timeFrom;
    按钮timeFromEdit;
    TextView的timeTo;
    按钮timeToEdit;
    TextView的关键词;

    复选框matchCase;
    复选框matchAlone;
    复选框matchPlural;

    按钮来取消;
    按钮保存;


}

活动活性;
ViewHolder持有人;
片段片段



公共查看initViews(片段mFragment,规则rule){
    片段= mFragment;
    活性= fragment.getActivity();
    查看dialogView = LayoutInflater.from(活动).inflate(R.layout.rules_dialog,NULL);

    持有人=新ViewHolder(dialogView);

    最后的TextView发件人= holder.senders;

    holder.sendersAdd.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            showContacts();
        }});

    holder.sendersEdit.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            editSenders(发件人);

        }

    });

    最后的TextView timeFrom = holder.timeFrom;
    holder.timeFromEdit.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            showTimePickerDialog(timeFrom);

        }

        });

    最后的TextView timeTo = holder.timeTo;
    holder.timeToEdit.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            showTimePickerDialog(timeTo);

        }

        });


    holder.cancel.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            mListener.onCancel();

        }});
    holder.save.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            mListener.onSave(保持器);

        }});


    如果(规则== NULL)
        规则=新规则();


    holder.name.setText(rule.name);
    holder.response.setText(rule.response);

    holder.senders.setText(rule.senders.toString());
    holder.senders.setTag(rule.senders);

    holder.keywords.setText(rule.keywords);

    holder.matchCase.setChecked(rule.matchCase);
    holder.matchAlone.setChecked(rule.matchAlone);
    holder.matchPlural.setChecked(rule.matchPlural);

    holder.timeFrom.setTag(rule.timeFrom);
    holder.timeFrom.setText(Rules.formatTime(rule.timeFrom));

    holder.timeTo.setTag(rule.timeTo);
    holder.timeTo.setText(Rules.formatTime(rule.timeTo));

    返回dialogView;
}
 

解决方案

于是,我就重写RulesDialog作为一个片段,它没有工作太清楚了。有问题使片段事务工作的权利,从他们工作的片段时调用。

(我知道这是不是点的片段。我真的不瞄准,现在写一个完全模块化的应用程序。我只是想拿出一个产品的客户会很乐意用。)

我最终改写RulesDialog作为一种活动,而是和从调用片段使用startActivityForResult()。然后使编辑后的数据回用的setResult()。这一切都工作得很好的演唱会。

Sorry if the title was a bit vague.

I'm developing an app on Freelancer and I almost have it finished except for a complaint from the customer after some testing.

I use a PopupWindow in place of a dialog to edit contextual settings, if that makes any sense. I don't want to be too specific and risk giving the app concept away, which I'm sure the customer wouldn't be too pleased about.

The PopupWindow is given a Content View of a layout inflated from XML. In that layout are several EditText widgets. The issue is that those EditTexts will not trigger the default contextual dialog on long press that presents options for text/IME selection, and cut/copy/paste.

I saw a similar question trying to get the TouchTrigger or something and it not working without setBackgroundDrawable(), which I've tried with a simple new ColorDrawable(). It still doesn't work.

Is there any easy way to trigger the system-default long-press dialog in an OnLongPressListener, or will I have to move Heaven and Earth to implement it myself? Because if that's the case, I'll just write a Fragment for it and swap it out in a transaction. I know that'll work.

The relevant code: Inside the initiating fragment:

RulesDialog dialog;
PopupWindow window;

public void showAddRuleDialog(){
    dialog = new RulesDialog();

    View view = getView();

    window = new PopupWindow(dialog.initViews(this, null), view.getWidth(), view.getHeight(), true);

    window.setBackgroundDrawable(new ColorDrawable());

    dialog.setRulesDialogListener(new rulesDialogListener(){            

        @Override
        public void onSave(ViewHolder holder) {


            addRule(holder);

            window.dismiss();


        }

        @Override
        public void onCancel() {
            window.dismiss();

        }});

    int[] location = {0,0};
    view.getLocationOnScreen(location);



    window.showAtLocation(view, 0, location[0], location[1]);

In RulesDialog:

public class ViewHolder{
    public ViewHolder(View dialogView){
        name = (TextView) dialogView.findViewById(R.id.name);
        response = (TextView) dialogView.findViewById(R.id.response);

        senders = (TextView) dialogView.findViewById(R.id.senders);
        sendersAdd = (Button) dialogView.findViewById(R.id.sendersAdd);
        sendersEdit = (Button) dialogView.findViewById(R.id.sendersEdit);

        timeFrom = (TextView) dialogView.findViewById(R.id.from);
        timeFromEdit = (Button) dialogView.findViewById(R.id.timeBeforeEdit);
        timeTo = (TextView) dialogView.findViewById(R.id.to);
        timeToEdit = (Button) dialogView.findViewById(R.id.timeAfterEdit);

        keywords = (TextView) dialogView.findViewById(R.id.keywords);

        matchCase = (CheckBox) dialogView.findViewById(R.id.matchCase);
        matchAlone = (CheckBox) dialogView.findViewById(R.id.matchAlone);
        matchPlural = (CheckBox) dialogView.findViewById(R.id.matchPlural);

        cancel = (Button) dialogView.findViewById(R.id.cancel);
        save = (Button) dialogView.findViewById(R.id.save);


    }

    TextView name;
    TextView response;
    TextView senders;
    Button sendersAdd;
    Button sendersEdit;
    TextView timeFrom;
    Button timeFromEdit;
    TextView timeTo;
    Button timeToEdit;
    TextView keywords;

    CheckBox matchCase;
    CheckBox matchAlone;
    CheckBox matchPlural;

    Button cancel;
    Button save;


}

Activity activity;
ViewHolder holder;
Fragment fragment;



public View initViews(Fragment mFragment, Rule rule){
    fragment = mFragment;
    activity = fragment.getActivity();
    View dialogView = LayoutInflater.from(activity).inflate(R.layout.rules_dialog, null);

    holder = new ViewHolder(dialogView);

    final TextView senders = holder.senders;

    holder.sendersAdd.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            showContacts();
        }});

    holder.sendersEdit.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            editSenders(senders);

        }

    });

    final TextView timeFrom = holder.timeFrom;
    holder.timeFromEdit.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            showTimePickerDialog(timeFrom);             

        }

        });

    final TextView timeTo = holder.timeTo;
    holder.timeToEdit.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            showTimePickerDialog(timeTo);               

        }

        });


    holder.cancel.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            mListener.onCancel();

        }});        
    holder.save.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            mListener.onSave(holder);

        }});


    if(rule == null)
        rule = new Rule();


    holder.name.setText(rule.name);
    holder.response.setText(rule.response);

    holder.senders.setText(rule.senders.toString());
    holder.senders.setTag(rule.senders);                

    holder.keywords.setText(rule.keywords);

    holder.matchCase.setChecked(rule.matchCase);
    holder.matchAlone.setChecked(rule.matchAlone);
    holder.matchPlural.setChecked(rule.matchPlural);        

    holder.timeFrom.setTag(rule.timeFrom);                          
    holder.timeFrom.setText(Rules.formatTime(rule.timeFrom));

    holder.timeTo.setTag(rule.timeTo);
    holder.timeTo.setText(Rules.formatTime(rule.timeTo));

    return dialogView;
}

解决方案

So I tried rewriting RulesDialog as a fragment, and it didn't work out too well. Had issues with making Fragment Transactions work right when called from the Fragments they're operating on.

(I know this isn't the point to fragments. I'm not really aiming to write a completely modular app right now. I just want to come out with a product the customer will be happy with.)

I ended up rewriting RulesDialog as an Activity instead, and using startActivityForResult() from the calling fragment. Then passing the edited data back with setResult(). It all works nicely in concert.

这篇关于PopupWindow不长的EditText preSS触发系统正语境对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆