简体   繁体   English

我的按钮不工作,我怎样才能让它在 android studio 上工作?

[英]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.

相关问题 Android切换按钮仅工作一次。 我如何每次都能使用? - Android toggle button just working once. How can i make it work every time? 如何使我的Android应用程序的按钮时尚 - How can I make the button stylish for my android app 如何让我的ActionBar的“向上”按钮像手机的“后退”按钮一样工作? - How can I make my ActionBar's “Up” button work like the phone's “Back” button? Android Studio - 按下按钮后如何让我的 RecyclerView 包含更多项目? - Android Studio - How do I make my RecyclerView contain more items after a button press? 如何在 Android Studio 中使用布局? - How can I work with layouts in Android Studio? Android Studio-每次单击按钮时如何在线性布局上生成新的textview - Android Studio - How can I generate a new textview on my linear layout every time i click a button 我如何进行从按钮到新活动的 animation 转换?[Android Studio] - How i can make a animation transition that start from a button to a new activity?[Android Studio] 我如何在android中制作发光按钮 - How can i make a glow button in android 我的按钮在 android studio 中不起作用 - My button won't work in android studio 如何在 android 工作室中将我的浮动按钮对齐到页面底部 - how can i align my floating button to the bottom of the page in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM