Android View.setOnTouchListener未在Fragment中调用

时间:2016-12-21 16:24:27

标签: android view fragment motionevent ontouch

如何从View获取MotionEvent?

 public class PhotoGalleryFragment extends Fragment implements View.onTouchListener {

  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_photo_gallery, container, false);
        recyclerPhotoView = (RecyclerView) view.findViewById(R.id.photo_gallery_list);

        view.setOnTouchListener(this);

        return view;
    }

@Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
            Toast.makeText(getContext(), "Row " + motionEvent.getAction() + " clicked!", Toast.LENGTH_SHORT).show();
            return true;
        } else
            return false;
    }
  }

0 个答案:

没有答案