片段工具OnClickListener [英] Fragment implements OnClickListener

查看:82
本文介绍了片段工具OnClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我正在现代化的应用程序。此过程中的一个步骤是改变到一个片段为基础的布局(使用片段从支撑库)。 我将我的活动成了碎片,并得到了布局很好地工作(使用ViewPager,很酷的东西!)

I've got an application that I'm modernizing. One step of this process is changing to a Fragment based layout (using the Fragments from the support library). I converted my Activities into Fragments, and got the layout working nicely (using a ViewPager, cool stuff!)

我有我的活动实现OnClickListener我所有的按钮 - pressing需求。我有新的片段变身做,当然同样的事情,但它看起来像的onClick从来没有击中。是否有$ P $从这种方式工作pvents呢?什么特别的片段

I was having my Activities implement OnClickListener for all of my button-pressing needs. I have the new Fragment incarnations doing the same thing of course, but it looks like "onClick" is never getting hit. Is there something special about Fragments that prevents them from working this way?

推荐答案

只是做一本

public class fragmentOne extends Fragment implements OnClickListener {
    Button myButton;

    @Override
    public View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedinstanceState) {
        View myView = inflater.inflate(R.layout.fragment_1, container, false);
        myButton = (Button) myView.findViewById(R.id.myButton);
        myButton.setOnClickListener(this);
        return myView;
    }

    @Override
    public void onClick(View v) {
        // implements your things
    }
}

很简单

这篇关于片段工具OnClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆