gpt4 book ai didi

Android button.setOnClickListener

转载 作者:行者123 更新时间:2023-11-30 00:29:43 26 4
gpt4 key购买 nike

我正在使用 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;
}
}

最佳答案

    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;
}
}

关于Android button.setOnClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44664181/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com