我正在使用具有自定义警报布局的自定义警报对话框。并添加了一个按钮。当我单击按钮时,它应该敬酒消息。但是,当我单击该按钮不起作用时,什么也没有发生。请参见下面的代码
private void showCustomDialog(String topText) {
//before inflating the custom alert dialog layout, we will get the current activity viewgroup
ViewGroup viewGroup = findViewById(android.R.id.content);
//then we will inflate the custom alert dialog xml that we created
View dialogView = LayoutInflater.from(this).inflate(R.layout.custom_dialog, viewGroup, false);
//Now we need an AlertDialog.Builder object
AlertDialog.Builder builder = new AlertDialog.Builder(SpinningWheel.this);
//setting the view of the builder to our custom view that we already inflated
builder.setView(dialogView);
TextView youwon= dialogView.findViewById(R.id.youwon);
climebtn =dialogView.findViewById(R.id.buttonOk);
climebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(SpinningWheel.this,"You Just Claimed the Reward",Toast.LENGTH_LONG);
}
});
youwon.setText("You Won "+topText+" Points");
//finally creating the alert dialog and displaying it
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
和我的自定义布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/white"
tools:context=".Activity.SpinningWheel"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/colorPrimary">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="@drawable/ic_success" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<prokart.in.app.font.RobotoTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Congratulations"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<com.airbnb.lottie.LottieAnimationView
android:layout_below="@id/a"
android:layout_width="wrap_content"
app:lottie_fileName="bidsuccess.json"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/twentydp"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
<prokart.in.app.font.RobotoTextView
android:id="@+id/youwon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="10dp"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<prokart.in.app.font.RobotoTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:text="Keep Playing! Keep Winning"
android:textColor="@color/green"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<Button
android:id="@+id/buttonOk"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:clickable="true"
android:background="@drawable/round_cornor_primery"
android:text="Claim This Reward"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
在Oncreate
中我叫showCustomDialog(topText)
。如何使按钮使用这种方法,请提出建议。