I’m learning how to code in Java after you come from C. In C, I have always divided everything into separate functions to make the code more convenient for further editing and editing. I tried to do this in java, but now, since I realized that you cannot use pointers, I'm a little confused that the best way to do this is.
So, for example, I want to have a method that generates four warnings for me. Therefore, I give him the alert creator, who can then generate alerts. I can return them to an array, but in my code I already have alerts individually named, and I would like to save it that way, so I would not need to refer to them as a warning [1], alert [2]. .. etc.
So this means that I would have to rename them, which would add additional code, which would probably be longer than the code in the real method!
I think about it right? Is there anything I can do?
-Edit-
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(this.getString(R.string.ache_Q_text))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {dialog.cancel();}
});
final AlertDialog ache_Q_alert = builder.create();
builder.setMessage(this.getString(R.string.food_Q_text));
final AlertDialog food_Q_alert = builder.create();
builder.setMessage(this.getString(R.string.event_Q_text));
final AlertDialog event_Q_alert = builder.create();
builder.setMessage(this.getString(R.string.ache_Q_text));
final AlertDialog ache_type_Q_alert = builder.create();
and instead replace it with
createAlerts();
and this code is off somewhere on the side.
source
share