I’m trying to control the text and the button on my custom dialog.
but for some reason when calling the text and the button, the dialog doesn’t show.
I need to delete the text and button part for the dialog to show. Why is that happening?
private void showMessage()
{
Dialog dialog = new Dialog(Test2.this);
dialog.setContentView(R.layout.finish_question);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
TextView finalScore = dialog.findViewById(R.id.finalScore);
AppCompatButton close = dialog.findViewById(R.id.close);
finalScore.setText(score);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
finish();
}
});
dialog.show();
}
you can see that I have called the elements the right way, by using dialog.findViewById
, so why isn’t working?
Here is my layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_margin="20dp"
android:background="@drawable/rounded_button"
android:orientation="vertical"
android:gravity="center"
android:padding="10dp"
android:layout_height="match_parent">
<TextView
android:textSize="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="النتيجة:"
android:gravity="center"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/finalScore"
android:textColor="@color/black"
android:textSize="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:gravity="center" />
<TextView
android:textSize="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/5"
android:textColor="@color/black"
android:gravity="center" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/close"
android:text="إنهاء"
android:layout_margin="10dp"
android:textColor="@color/white"
android:background="@drawable/rounded_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>