Android 尝试双击片段启动电子邮件应用程序

Android 尝试双击片段启动电子邮件应用程序,android,android-fragmentactivity,gesture-recognition,Android,Android Fragmentactivity,Gesture Recognition,我正在创建一个简单的主详细信息应用程序,我希望用户能够双击详细信息视图屏幕,并从设备打开默认的电子邮件应用程序对话框。下面是我的TopicDetalsFrament.java文件。请帮助我理解OnDoubleTapListener代码不起作用的原因 public class TopicDetailFragment extends Fragment implements OnDoubleTapListener { /** * The fragment argument representing

我正在创建一个简单的主详细信息应用程序,我希望用户能够双击详细信息视图屏幕,并从设备打开默认的电子邮件应用程序对话框。下面是我的TopicDetalsFrament.java文件。请帮助我理解OnDoubleTapListener代码不起作用的原因

public class TopicDetailFragment extends Fragment implements OnDoubleTapListener
{
/**
 * The fragment argument representing the item ID that this fragment
 * represents.
 */
public static final String ARG_ITEM_ID = "item_id";

/**
 * The topic content this fragment is presenting.
 */
private TopicArrayContent.TopicArrayItem mItem;

/**
 * Mandatory empty constructor for the fragment manager to instantiate the
 * fragment (e.g. upon screen orientation changes).
 */
public TopicDetailFragment() 
{

}

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    if (getArguments().containsKey(ARG_ITEM_ID)) 
    {
        // Load the content specified by the fragment arguments. 
        mItem = TopicArrayContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
    }

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) 
{
    View rootView = inflater.inflate(R.layout.fragment_topic_detail, container, false);

    // Show the Scriptures content as text in a TextView.
    if (mItem != null) 
    {           
        ((TextView) rootView.findViewById(R.id.topic_scripture1)).setText(mItem.scripture1);
        ((TextView) rootView.findViewById(R.id.topic_scripture2)).setText(mItem.scripture2);
        ((TextView) rootView.findViewById(R.id.topic_scripture3)).setText(mItem.scripture3);
        ((TextView) rootView.findViewById(R.id.topic_scripture4)).setText(mItem.scripture4);
        ((TextView) rootView.findViewById(R.id.topic_scripture5)).setText(mItem.scripture5);
        ((TextView) rootView.findViewById(R.id.topic_scripture6)).setText(mItem.scripture6);
        ((TextView) rootView.findViewById(R.id.topic_scripture7)).setText(mItem.scripture7);
        ((TextView) rootView.findViewById(R.id.topic_name)).setText(mItem.topicName);
    }
    return rootView;        

}

@Override
public boolean onDoubleTap(MotionEvent e) {
    // TODO Auto-generated method stub
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL,
            new String[] { "Enter recipient's email address" });
    i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    i.putExtra(Intent.EXTRA_TEXT, "body of email");
    try {
        startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(TopicDetailFragment.this.getActivity(),
                "There are no email clients installed.",         Toast.LENGTH_LONG)
                .show();
    }
    return true;
}

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    // TODO Auto-generated method stub      
    return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}   

}
非常感谢您提供的任何帮助/建议


SonCoder

嗯,你只是没有注册任何事件。实现接口不会神奇地向您传递tap事件。您必须将片段作为侦听器安装

请参阅,并在onCreate方法中使用片段作为回调来设置手势检测器



除此之外:IMHO,这种模式在Android上不是好的实践。用户将不知道必须双击屏幕才能执行操作。为什么不提供一个可点击的电子邮件地址(请参阅默认的Android People应用程序)或操作栏菜单项?

我发现了很多关于如何在活动中实现这一点的信息,但关于在片段中实现的信息不多。我是一个初学者,但是,还有很多东西要学。有人有什么想法吗?有没有更好的方法来使用示例/教程?请欣赏有关使用可单击电子邮件地址的提示。我会把它作为首选方案。还感谢“手势检测培训”的链接。很高兴能够提供帮助:)