简体   繁体   English

Android Presentation可以处理触摸事件吗?

[英]Can Android Presentation handle touch events?

I know that Android Presentations can have their own layouts which means I can create UI components like buttons etc. However, does anyone know if it is possible for Presentations to handle touch events? 我知道Android 演示文稿可以有自己的布局,这意味着我可以创建按钮等UI组件。但是,有人知道演示文稿是否可以处理触摸事件吗?

I have tried adding a button on the Presentation layout and registering a button onClickListener but it seems to not be working. 我尝试在Presentation布局上添加按钮并在onClickListener上注册按钮,但它似乎无法正常工作。 Is there another way? 还有另一种方法吗?

Here is my code: 这是我的代码:

In my Presentation class 在我的演讲班

mHelloToast = (Button) findViewById(R.id.btn_presentation_hello_toast);
    mHelloToast.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast toast = Toast.makeText(getContext(), "hello presentation", Toast.LENGTH_SHORT );
            toast.show();
        }
    });

Edit: bump 编辑:凹凸

Doc says: Doc说:

A presentation is a special kind of dialog whose purpose is to present content on a secondary display. 演示是一种特殊的对话框,其目的是在辅助显示器上演示内容。 A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the display's metrics. Presentation在创建时与目标Display关联,并根据Display的指标配置其上下文和资源配置。

So I think Android Presention can handle touche event as Dialog .Here I will show you how Dialog handles touch event. 所以我认为Android Presention可以像Dialog一样处理touche事件。在这里,我将向您展示Dialog如何处理touch事件。

Step 1 第1步

Create your custom layout res/layout/dialog_signin.xml . 创建您的自定义布局res/layout/dialog_signin.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/btn_presentation_hello_toast"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

Step 2 第2步

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Get the view which you want to receive touch event
//// Pass null as the parent view because its going in the dialog layout
View rootView = inflater.inflate(R.layout.dialog_signin, null);
Button bt = (Button)rootView.findViewById(R.id.btn_presentation_hello_toast);
// set click or touch listener
bt.setOnClickListener(....);

// set dialog's contents
builder.setView(rootView);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM