I am having a problem which is hindering the usability of my app. To explain, I have a production line tracker app which tracks whether they are on target. They fill in their actual and I have background calculations happening which tells them whether they are ahead or behind. My main activity is a dashboard of the production lines so they can see at a glance.
The problem is that I had all of my IF statements on my main activity so that the dashboard would update automatically, however, I was getting a lot of null pointers as the user has not reached the page to fill in the data yet and therefore null pointers occur.
I added refresh buttons to each of the lines and put the IF statements behind this and it is working, however, they have came back and said that this is an extra click and they want it to update automatically.
Would anyone know any way round this?
Here is the Refresh button code:
Button RefreshS1 = findViewById(R.id.refreshS1);
RefreshS1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (spinnerSelection == null || spinnerSelection2 == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Data Input Error");
builder.setMessage("Line S1 Data has not been entered yet!");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("20")) {
if (actualshippersnum == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Refresh Error");
builder.setMessage("Cannot Refresh! Please Fill in Line Details");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
else if (actualshippersnum > optimum20) {
PB4 = findViewById(R.id.roundCornerProgressBar4);
PB4.setProgressColor(Color.rgb(69, 173, 88));
PB4.setMax(100);
PB4.setProgress(diffplus20);
Toast.makeText(Dashboard.this, "Line S1: " + percentageActual20+ "% Complete", Toast.LENGTH_LONG).show();
} else if (actualshippersnum < optimum20) {
PB4 = findViewById(R.id.roundCornerProgressBar4);
PB4.setProgressColor(Color.rgb(242, 33, 33));
PB4.setMax(100);
PB4.setProgress(diffminus20);
} else if (actualshippersnum == optimum20) {
PB4 = findViewById(R.id.roundCornerProgressBar4);
PB4.setProgressColor(Color.rgb(28, 78, 173));
PB4.setMax(100);
PB4.setProgress(percentageActual20);
} else if (spinnerSelection.equals("S1") && spinnerSelection2.equals("30")) {
if (actualshippersnum == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Refresh Error");
builder.setMessage("Cannot Refresh! Please Fill in Line Details");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else
if (actualshippersnum > optimum30) {
PB4 = findViewById(R.id.roundCornerProgressBar4);
PB4.setProgressColor(Color.rgb(69, 173, 88));
PB4.setMax(100);
PB4.setProgress(diffplus30);
} else if (actualshippersnum < optimum30) {
PB4 = findViewById(R.id.roundCornerProgressBar4);
PB4.setProgressColor(Color.rgb(242, 33, 33));
PB4.setMax(100);
PB4.setProgress(diffminus30);
} else if (actualshippersnum == optimum30) {
PB4 = findViewById(R.id.roundCornerProgressBar4);
PB4.setProgressColor(Color.rgb(28, 78, 173));
PB4.setMax(100);
PB4.setProgress(percentageActual30);
}
}
}
}
});
Button RefreshS2 = findViewById(R.id.refreshS2);
RefreshS2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (spinnerSelection == null || spinnerSelection2 == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Data Input Error");
builder.setMessage("Line S2 Data has not been entered yet!");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("20")) {
if (actualshippersnum == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Refresh Error");
builder.setMessage("Cannot Refresh! Please Fill in Line Details");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else
if (actualshippersnum > optimum20) {
PB5 = findViewById(R.id.roundCornerProgressBar5);
PB5.setProgressColor(Color.rgb(69, 173, 88));
PB5.setMax(100);
PB5.setProgress(diffplus20);
} else if (actualshippersnum < optimum20) {
PB5 = findViewById(R.id.roundCornerProgressBar5);
PB5.setProgressColor(Color.rgb(242, 33, 33));
PB5.setMax(100);
PB5.setProgress(diffminus20);
} else if (actualshippersnum == optimum20) {
PB5 = findViewById(R.id.roundCornerProgressBar5);
PB5.setProgressColor(Color.rgb(28, 78, 173));
PB5.setMax(100);
PB5.setProgress(percentageActual20);
}
} else if (spinnerSelection.equals("S2") && spinnerSelection2.equals("30")) {
if (actualshippersnum == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Refresh Error");
builder.setMessage("Cannot Refresh! Please Fill in Line Details");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else
if (actualshippersnum > optimum30) {
PB5 = findViewById(R.id.roundCornerProgressBar5);
PB5.setProgressColor(Color.rgb(69, 173, 88));
PB5.setMax(100);
PB5.setProgress(diffplus30);
} else if (actualshippersnum < optimum30) {
PB5 = findViewById(R.id.roundCornerProgressBar5);
PB5.setProgressColor(Color.rgb(242, 33, 33));
PB5.setMax(100);
PB5.setProgress(diffminus30);
} else if (actualshippersnum == optimum30) {
PB5 = findViewById(R.id.roundCornerProgressBar5);
PB5.setProgressColor(Color.rgb(28, 78, 173));
PB5.setMax(100);
PB5.setProgress(percentageActual30);
}
}
}
});
Button RefreshS3 = findViewById(R.id.refreshS3);
RefreshS3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (spinnerSelection == null || spinnerSelection2 == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Data Input Error");
builder.setMessage("Line S3 Data has not been entered yet!");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else if (spinnerSelection.equals("S3") && spinnerSelection2.equals("20")) {
if (actualshippersnum == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Refresh Error");
builder.setMessage("Cannot Refresh! Please Fill in Line Details");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else
if (actualshippersnum > optimum20) {
PB6 = findViewById(R.id.roundCornerProgressBar6);
PB6.setProgressColor(Color.rgb(69, 173, 88));
PB6.setMax(100);
PB6.setProgress(diffplus20);
} else if (actualshippersnum < optimum20) {
PB6 = findViewById(R.id.roundCornerProgressBar6);
PB6.setProgressColor(Color.rgb(242, 33, 33));
PB6.setMax(100);
PB6.setProgress(diffminus20);
} else if (actualshippersnum == optimum20) {
PB6 = findViewById(R.id.roundCornerProgressBar6);
PB6.setProgressColor(Color.rgb(28, 78, 173));
PB6.setMax(100);
PB6.setProgress(percentageActual20);
}
else if (spinnerSelection.equals("S3") && spinnerSelection2.equals("30")) {
if (actualshippersnum == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Dashboard.this);
builder.setTitle("Refresh Error");
builder.setMessage("Cannot Refresh! Please Fill in Line Details");
builder.setIcon(R.drawable.warning_icon);
builder.setCancelable(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else
if (actualshippersnum > optimum30) {
PB6 = findViewById(R.id.roundCornerProgressBar6);
PB6.setProgressColor(Color.rgb(69, 173, 88));
PB6.setMax(100);
PB6.setProgress(diffplus30);
} else if (actualshippersnum < optimum30) {
PB6 = findViewById(R.id.roundCornerProgressBar6);
PB6.setProgressColor(Color.rgb(242, 33, 33));
PB6.setMax(100);
PB6.setProgress(diffminus30);
} else if (actualshippersnum == optimum30) {
PB6 = findViewById(R.id.roundCornerProgressBar6);
PB6.setProgressColor(Color.rgb(28, 78, 173));
PB6.setMax(100);
PB6.setProgress(percentageActual30);
}
}
}
}
});
Aucun commentaire:
Enregistrer un commentaire