its not working. I don't know what's wrong
When the b are pressed, the white screen disappears.
popup layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="350dp"
android:layout_height="450dp"
android:layout_gravity="center"
android:background="@color/dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MissingConstraints">
<ImageView
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_marginBottom="10dp"
android:contentDescription="@string/kara"
android:src="@drawable/win" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/con"
android:textColor="@color/white"
android:layout_gravity="center"
android:fontFamily="@font/advent_pro_medium"
android:textSize="24sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/win"
android:textColor="@color/white"
android:layout_gravity="center"
android:fontFamily="@font/advent_pro_medium"
android:textSize="24sp"
android:layout_marginTop="25dp"/>
<TextView
android:id="@+id/winnerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/winNameKara"
android:textColor="@color/white"
android:layout_gravity="center"
android:fontFamily="@font/advent_pro_medium"
android:textSize="24sp"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/homeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:background="@drawable/button_style"
android:text="@string/pop" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Main layout code
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
.
<TextView
android:id="@+id/playerText1"
android:layout_width="110dp"
android:layout_height="28dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/advent_pro_medium"
android:text="@string/player1"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="#D5D5D5"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
.
</androidx.constraintlayout.widget.ConstraintLayout>
main code
When the b are pressed, the white screen disappears.
TextView p1name;
p1name = findViewById(R.id.playerText1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
win();
}
});
.
.
.
public void win(){
TextView winName;
Button home;
winName = mDialog.findViewById(R.id.winnerName);
home = mDialog.findViewById(R.id.homeButton);
mDialog.getWindow().setBackgroundDrawable(new
ColorDrawable(Color.TRANSPARENT));
mDialog.setContentView(R.layout.winpopup);
.
**winName = p1name; <----- pass value name** <---When this line arrives,
the application will display a white screen and an error
.
// winName.setText("HELLO");
home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
**mDialog.dismiss(); <----- dialog close** <--- or When this line
arrives, the application will display a white screen and an error
}
});
mDialog.show();
}
pass value main layout to sublayout TextView value
and
There is an error just pressing the button(home) in sublayout
When the b are pressed, the white screen disappears.
When the b are pressed, the white screen disappears.
When the b are pressed, the white screen disappears.
When the b are pressed, the white screen disappears.
question from:
https://stackoverflow.com/questions/65862291/how-to-pass-value-to-another-popup-layout-in-android-studio 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…