0

I am trying to create an application which when a button from a popup window is clicked a new button will be created in another layout of the same activity.

Here is the code for the popupwindow.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:id="@+id/start_goal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/start_goal" />


</RelativeLayout>

Here is the code for the activitymain.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context="com.example.eugene.trackeruptest3.MainActivity"
    android:background="@color/darkgrey"
    android:orientation="vertical">  

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="355dp">

                <Button
                    android:id="@+id/setupgoal"
                    android:layout_width="350dp"
                    android:layout_height="wrap_content"
                    android:text="@string/setup_goal"
                    android:textSize="25sp" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/buttonContainer">

        </RelativeLayout>
    </LinearLayout> 

Here is the java code for the popupwindow

public class creategoal extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    setContentView(R.layout.popupwindow);

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    int width = dm.widthPixels;
    int height = dm.heightPixels;

    getWindow().setLayout((int)(width*.8),(int)(height*.6));
  }
}

And here is the java code for the MainActivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button setupgoal = (Button) findViewById(R.id.setupgoal);

    setupgoal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(MainActivity.this,creategoal.class));
        }
    });
  }
}
Waffles
  • 1
  • 2

1 Answers1

1

Have you tried using visibility:gone on your XML and setting it with view.setVisibility(Visibility.VISIBLE); on your onClick method?

Valentin Michalak
  • 2,089
  • 1
  • 14
  • 27
Jose Riballo
  • 308
  • 2
  • 12