[英]My button is not working, how can i make it work on android studio?
I made a button on my android studio project and I'm pretty sure the code is just fine.我在我的 android studio 项目上做了一个按钮,我很确定代码很好。 the problem is that the button does not respond - I click it, but it doesn't give me the wanted result.
问题是按钮没有响应 - 我点击它,但它没有给我想要的结果。 If you could help, please do.
如果你能帮忙,请帮忙。 thank you so much for your time!
非常感谢您的参与!
this is the code:这是代码:
XML file code: XML文件代码:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Bdateofbirth"
android:text="Date of birth"
android:gravity="center"
android:layout_gravity="center"/>
onClick Code:点击代码:
@Override
public void onClick(View view) {
if (view == Bdateofbirth) {
dialogDOB();
}
}
dialogDOB:对话DOB:
private void dialogDOB(){
Calendar calendar = Calendar.getInstance();
int d = calendar.get(Calendar.DAY_OF_MONTH);
int m = calendar.get(Calendar.MONTH);
int y = calendar.get(Calendar.YEAR);
DatePickerDialog datePickerDialog = new DatePickerDialog(signup.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
i1=i1+1;
String date = i + "/" + i1 + "/" + i2;
Toast.makeText(signup.this, date, Toast.LENGTH_SHORT).show();
Bdateofbirth.setText(date);
}
}, d, m, y);
datePickerDialog.show();
}
THANK YOU谢谢你
In your Activity's XML file, add the attribute android:onclick="onClick"
for your button to connect it to your onClick
method.在您的活动的 XML 文件中,为您的按钮添加属性
android:onclick="onClick"
以将其连接到您的onClick
方法。 You don't need the @override
.你不需要
@override
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.