[英]Button onclick not firing the event in Android
Here is my button on click listener. 这是我在点击监听器上的按钮。 I am trying to listen to the onclick event firing.
我正在尝试监听onclick事件触发。 But it is not working.
但这是行不通的。 I have tried the method given in develop.android.com.
我已经尝试了develop.android.com中给出的方法。 But this method seems to be not working.
但是这种方法似乎行不通。 Can anyone point out the mistake that I am doing here?
谁能指出我在这里犯的错误?
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
v = inflater.inflate(R.layout.product_fragment, container, false);
Button button = (Button) v.findViewById(R.id.buynow_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getActivity(), "test", 2000);
}
});
return v;
}
您没有在Toast上调用show函数。
Toast.makeText(getActivity(), "test", 2000).show();
Toast.makeText(getActivity(), "test", 2000);
需要更改为:
Toast.makeText(getActivity(), "test", Toast.LENGTH_SHORT).show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.