Excuse me if this is an easy problem. I have been unable to find an answer so far.I have followed this tutorial( https://www.youtube.com/watch?v=fn5OlqQuOCk ) to create a pop up window. While it works as intended I want to change the text when the button is pressed from the java code.
To be more specific, I have a string array and whenever the button is pressed I want it to show a random element of the array. How can I go about doing those things?
My onCreate method is(mundaneLoot is the id of the button):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.mundaneLoot);
b.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Pop.class ));
}
});
}
My xml code for the pop up window (which essentially is a new activity) is:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Pop up window"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
I want to edit the android:text="Pop up window" from the java code.
Activityhe is opening in hisIntentIS a popup.