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?
I have tried adding a button on the Presentation layout and registering a button onClickListener but it seems to not be working. 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:
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.
So I think Android Presention
can handle touche event as Dialog
.Here I will show you how Dialog
handles touch event.
Create your custom layout 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>
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.