LoginSignup
2
3

More than 5 years have passed since last update.

【Xamarin】AndroidのFragmentでタッチイベントを取得する

Posted at

Xamarin.Formを使わずにタッチイベント

Xamarin.Formを使わずに、Fragmentでタッチイベントを取得したかっただけなのに、かなり苦労してしまったので、メモメモ。

環境

XamarinStudio6.1.2
ソリューション:App"Native(iOS,Android)"
Shared Code:"Use Portable Class Library"

コード

検索するとSetOnTouchListenerを使う的なことが書かれてますが、これではエラーになってしまいます。
こちらが正解のようです。
ボタンのイベントとかと同じ方法ですね。

Fragment.cs
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view = base.OnCreateView(inflater, container, savedInstanceState); // タッチイベントを取得したいビュー
    view.Touch += (object sender, View.TouchEventArgs e) => 
    {
        // タッチした時の処理
    };

    return view;
}
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3