1

ユーザーが詳細表示画面をダブルタップして、デバイスからデフォルトの電子メールアプリケーションダイアログを開くことができるようにする単純なマスター/詳細アプリケーションを作成しています。以下に添付されているのは、私の 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;
}   

}

あなたが与えることができるどんな助け/提案にも感謝します,

ソンコーダー

4

1 に答える 1

2

まあ、あなたは単にイベントに登録していません。インターフェイスを実装しても、魔法のようにタップ イベントが配信されるわけではありません。フラグメントをリスナーとしてインストールする必要があります。

ジェスチャ検出トレーニングを参照し、 onCreate メソッドのコールバックとしてフラグメントを使用してジェスチャ検出器を設定します。


それとは別に、私見ですが、このパターンはAndroidではお勧めできません。ユーザーは、アクションを実行するために画面をダブルタップする必要があることを知りません。クリック可能な電子メール アドレス (デフォルトの Android People アプリケーションを参照) またはアクション バー メニュー エントリを提供しないのはなぜですか?

于 2013-08-05T14:04:45.903 に答える