1

我正在使用 tabbedActivity 制作一个用于研究的应用程序,加上按钮没有采取行动,有人知道解释原因,我尝试了几种形式,但都没有采取行动,不给出错误并破坏应用程序,但按钮什么也没有

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rooView = inflater.inflate(R.layout.fragment_teste, container, false);
        final Context context = getContext();
        button = (Button) rooView.findViewById(R.id.button);
        button.setOnClickListener((View.OnClickListener) this);
        return rooView;
    } 

@Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                Toast.makeText(getContext(), "Teste", Toast.LENGTH_LONG).show();
                break;
        }
    }
4

1 回答 1

1
    Button button;
    View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rooView = inflater.inflate(R.layout.fragment_teste, container, false);
        button = (Button) rooView.findViewById(R.id.btConfirm);
        button.setOnClickListener(this);
        return rooView;
    } 

@Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btConfirm:
                Toast.makeText(getActivity(), "Teste", Toast.LENGTH_LONG).show();
                break;
        }
    }
于 2017-06-21T01:27:56.497 回答