AppWidgetHostView无法处理的onClick / onLongClick正确 [英] AppWidgetHostView can't handle onClick/onLongClick properly

查看:244
本文介绍了AppWidgetHostView无法处理的onClick / onLongClick正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个发射器,现在我用的应用程序部件的工作,我跟着从这里的教程: AppWigetHost tutrial - 莱昂纳多·菲舍尔 一切顺利的话,直到我尝试添加onLongCick监听器上的AppWidgetHostView

I am developing a launcher, now I am working with app widgets, I follow the tutorial from here: AppWigetHost tutrial - Leonardo Fischer Everything goes well until I tried adding onLongCick listener on the AppWidgetHostView

private void createAppWidget(Intent data) {
    Bundle extras = data.getExtras();
    final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    AppWidgetHostView hostView = mAppWidgetHost.createView(getApplicationContext(), appWidgetId, appWidgetInfo);
    hostView.setAppWidget(appWidgetId, appWidgetInfo);
    LinearLayout.LayoutParams params = createLayoutParams(appWidgetInfo); 
    rootLayout.addView(hostView, params);
    hostView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(getApplicationContext(), "Long click " + appWidgetId, Toast.LENGTH_LONG).show();
            return true;
        }
    });
}

当我添加主机(默认的谷歌模拟时钟)上的一个小部件 - 并试图长期一下就可以了,这是行不通的!经过漫长的点击它只是打开时钟应用程序(默认操作点击)。

When I added a widget on the host (The default Google Analog Clock) - and tried to long click on it, it just doesn't work ! After the long click it just opens the Clock application (default action for click).

谁能告诉我如何解决它?这里是我的全code: http://pastebin.com/61TkuLvx

Can anyone tell me how to fix it ? Here is my full code: http://pastebin.com/61TkuLvx

添加 我刚刚检查了一遍:
  ----如果我渴望单击绑定的时钟部件后,longClick事件被解雇了!
  ----我加了我的自定义appwidget(没有onclick处理):使longclick事件总是发射正常。
所以我想,这一定有什么用的TouchEvent处理程序/调度员做。

Added I've just checked again:
----If I long click on the bound of the Clock widget, the longClick event is fired !
----I added my custom appwidget (which has no onclick handler): so the longclick event is always fired properly.
So I guess, it must have something with touchevent handler/dispatcher to do.

添加 我只是试图在hostview像这样的所有子集onLongClick:

Added I've just tried to set onLongClick on all children of the hostview like this:

private void createAppWidget(Intent data) {
...
... 
    setChildrenViewLongClick(hostView, new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(getApplicationContext(), "Long click " + appWidgetId, Toast.LENGTH_LONG).show();
            return true;
        }
    });
}

protected void setChildrenViewLongClick(View view, OnLongClickListener listener) {
    view.setOnLongClickListener(listener);
    String name = view.getClass().getName();
    Logger.logInfo("Classname: " + name);
    if ( view instanceof ViewGroup ) {
        ViewGroup vg = (ViewGroup) view;
        for(int i = 0 ; i < vg.getChildCount() ; i++ ) {
            setViewLongClick(vg.getChildAt(i), listener);
        }
    }
}

它只是不工作:(

奇怪的是:我做了另一个实验在一个又一个的活动,其中有一个LinearLayout中LL(有onLongClick处理器)包含2个按钮BT1,BT2 - (每个按钮都有onclick处理),并应用方法setChildrenViewLongClick(LL,onLongClickListener) - 然后长按上BT2 - WOOP,它的工作原理,内部onLongClickListener动作被称为!
因此,这是什么问题?所述AppWidgetHostView或事件/处理器调度程序?或者我(我的codeS)

It just doesn't work :(

The weird thing is: I did another experiment on a another activity, which has a Linearlayout LL( has onLongClick handler ) contains 2 buttons bt1,bt2 - (each button has onClick handler) And apply the method setChildrenViewLongClick(LL,onLongClickListener)- then long click on bt2 - Woop, it works, the action inside onLongClickListener is called !
So which is the problem ? The AppWidgetHostView or the event/handler dispatcher ? Or me (my codes)

我很困惑,请帮帮我!

韩国社交协会

推荐答案

些日子,没有从这么任何回答,我试图读取投石机,发射源$ C ​​$ C 原来很简单:扩展AppWidgetHostView和覆盖的方法onInterceptTouchEvent(),如<一href="https://github.com/tjlian616/Android-Trebuchet-Launcher-Standalone/blob/master/src/com/cyanogenmod/trebuchet/LauncherAppWidgetHostView.java" 。相对=nofollow>这个来源$ C ​​$ C - 我还没有尝试过,但我想它的工作:)

after some days without any answer from SO, I tried to read the source code of Trebuchet-launcher It turns out very simple: extends the AppWidgetHostView and override the method onInterceptTouchEvent() like this source code - I haven't tried it yet, but I guess it will work :).

希望这有助于任何人都和我一样:)

Hope this helps anyone like me :)

这篇关于AppWidgetHostView无法处理的onClick / onLongClick正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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