如何在Fragment中使用Onclick事件?

时间:2013-11-20 07:18:33

标签: android

使用片段,因为OntouchListener工作正常,但是onclick不能用于同一个View ...任何帮助?我的示例代码如下:

View view;

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

            **// Here the problem:  Onclick Listener is not working for a view** 

      view.setOnClickListener(new OnClickListener() {

      @Override 
           public void onClick(View v) { 

      Toast.makeText(getActivity(), "Please long press the key",
      Toast.LENGTH_LONG).show();
              Log.e("Click is working", "");

      } 
    });

         //  OnTouch is working fine for a view 

    view.setOnTouchListener(new SwipeDetector() {

        public void onSwipeTop() {

        }

        public void onSwipeRight() {

            if (mBitmap != null) {
                saveImage();

            }



        public void onSwipeLeft() {

        }

        public void onSwipeBottom() {

        }
     });

    return view;
     }

OnTouch可以正常使用View但是Onclick不适用于同一个视图...帮我... 提前谢谢..

0 个答案:

没有答案