I have created an pop up window that I can use to show important messages in my app. The code for this are written in PopActivity.
Here is my code:
public class PopActivity extends Activity {
private WorkOutClass the_workout_class = new WorkOutClass();
private TextView repTextField, setsTextField;
private Button den_knappen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop);
repTextField = (TextView) findViewById(R.id.repetitionID);
setsTextField = (TextView) findViewById(R.id.setsID);
den_knappen = (Button) findViewById(R.id.buttonID);
repTextField.setText("Reps : " + String.valueOf(the_workout_class.getReps()));
setsTextField.setText("Sets: " +String.valueOf(the_workout_class.getSets()));
DisplayMetrics thePopUpWindow = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(thePopUpWindow);
int width = thePopUpWindow.widthPixels;
int height = thePopUpWindow.heightPixels;
getWindow().setLayout((int)(width*.8), (int)(height*.7));
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = 20;
getWindow().setAttributes(params);
den_knappen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
the_workout_class.increaseReps();
repTextField.setText("Reps : " + String.valueOf(the_workout_class.getReps()));
setsTextField.setText("Sets: " +String.valueOf(the_workout_class.getSets()));
}
});
}}
My question is though: If i want to use the same type of pop-up window somewhere else in my app which provide a different message, is there a way I can just copy this to use it? Or do I need to create new file such as PopActivity2, PopActivity3 etc etc.?
Thanks for answer.