安卓:参考查看外片段|在片段的姿态监听器 [英] Android: reference to view outside fragment | gesture listener in fragments

查看:106
本文介绍了安卓:参考查看外片段|在片段的姿态监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段一个TextView,我想要的是检测的姿势时设置不同的文本。

I have a TextView in a fragment where I want to set different texts when gesture is detected.

@Override
public boolean onTouchEvent(MotionEvent event) {
    this.gestureDetector.onTouchEvent(event);
    return super.onTouchEvent(event);
}

以上code是用来听手势,但它只能在一个Activity类莫名其妙地使用,当我把 .onTouchEvent()在片段类,它说不能解析方法。
任何想法我怎么可以操纵片段或任何方式之外的观点基本上lsiten手势就像我在Activity类??

The above code is used to listen for gesture, but it can only be used in an Activity class somehow, when I put .onTouchEvent() in a fragment class, it says cannot resolve method. Any idea how I can manipulate a view from outside the fragment or any ways to basically lsiten for gesture like I did in the Activity class??

推荐答案

这将是更好的封装,如果你没有其他类潜入你的片段的查看和访问它。相反,有你的片段暴露做你想要什么,保持什么是你认为本地的片段的具体知识的方法。
如果是这种做法的一个障碍,建议,可能有一个模式来帮助你了吧。

It would be far better encapsulation if you didn't have another class dive into your fragment's view and access it. Instead, have your fragment expose a method to do what you want and keep the specific knowledge of what is in your view local to the Fragment. If there is an obstacle to that approach, advise and there's probably a pattern to help you over it.

这篇关于安卓:参考查看外片段|在片段的姿态监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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