我的主要活动包括7个按钮,这些按钮都会导致不同的活动,用户必须在其中键入数据。
public class DiagramNew extends AppCompatActivity {
Button mStateOne;
Button mStateTwo;
Button mStateThree;
Button mStateFour;
Button mQPump;
Button mQTurb;
Button mTemp;
Button mTester;
ProgressBar mProgress;
MotherDatabase myDbMain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagram_new);
myDbMain = new MotherDatabase(this, null, null, 8);
//Link each .xml component with the activity
mStateOne = (Button) findViewById(R.id.stateOneBtn);
mStateTwo = (Button) findViewById(R.id.stateTwoBtn);
mStateThree = (Button) findViewById(R.id.stateThreeBtn);
mStateFour = (Button) findViewById(R.id.stateFourBtn);
mQPump = (Button) findViewById(R.id.QPumpBtn);
mQTurb = (Button) findViewById(R.id.QTurbBtn);
mTemp = (Button) findViewById(R.id.TempBtn);
mTester = (Button) findViewById(R.id.testButton);
mProgress = (ProgressBar) findViewById(R.id.progressBar);
//Create OnClickListeners for each button
mStateOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeAskOne = new Intent(DiagramNew.this, DataStateOne.class);
startActivity(changeAskOne);
}
});
mStateTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeAskTwo = new Intent(DiagramNew.this, DataStateTwo.class);
startActivity(changeAskTwo);
}
});
mStateThree.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeAskThree = new Intent(DiagramNew.this, DataStateThree.class);
startActivity(changeAskThree);
}
});
mStateFour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeAskFour = new Intent(DiagramNew.this, DataStateFour.class);
startActivity(changeAskFour);
}
});
mQPump.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeAskPump = new Intent(DiagramNew.this, DataPump.class);
startActivity(changeAskPump);
}
});
mQTurb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeAskTurb = new Intent(DiagramNew.this, DataTurb.class);
startActivity(changeAskTurb);
}
});
mTemp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changeTemp = new Intent(DiagramNew.this, DataTemp.class);
startActivity(changeTemp);
}
});
mTester.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checkLength();
}
});
}
当用户通过点击按钮返回到Diagram活动时,我希望progressBar填满一点。以下是次要活动的样子:
public class DataStateOne extends AppCompatActivity {
EditText mS1ActualEnthalpy;
EditText mS1IdealEnthalpy;
EditText mS1ActualEntropy;
Button mSaveS1;
Button mDeleteS1;
MotherDatabase myDb;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_state_one);
mS1ActualEnthalpy = (EditText) findViewById(R.id.S1ActualEnthalpyInput);
mS1IdealEnthalpy = (EditText) findViewById(R.id.S1IdealEnthalpyInput);
mS1ActualEntropy = (EditText) findViewById(R.id.S1ActualEntropyInput);
mSaveS1 = (Button) findViewById(R.id.saveS1Btn);
mDeleteS1 = (Button) findViewById(R.id.button);
myDb = new MotherDatabase(this, null, null, 1);
mS1ActualEnthalpy.getBackground().mutate().setColorFilter(getResources().getColor(R.color.shadowEnd), PorterDuff.Mode.SRC_ATOP);
mS1IdealEnthalpy.getBackground().mutate().setColorFilter(getResources().getColor(R.color.shadowEnd), PorterDuff.Mode.SRC_ATOP);
mS1ActualEntropy.getBackground().mutate().setColorFilter(getResources().getColor(R.color.shadowEnd), PorterDuff.Mode.SRC_ATOP);
mSaveS1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mS1ActualEnthalpy.getText().toString().trim().length() > 0 && mS1IdealEnthalpy.getText().toString().trim().length() > 0 && mS1ActualEntropy.getText().toString().trim().length() > 0){
String S1ActualEnthalpyStr = mS1ActualEnthalpy.getText().toString();
String S1IdealEnthalpyStr = mS1IdealEnthalpy.getText().toString();
String S1ActualEntropyStr = mS1ActualEntropy.getText().toString();
Toast myToast = Toast.makeText(getApplicationContext(),"The data are " + S1ActualEnthalpyStr + ", " + S1IdealEnthalpyStr + ", " + S1ActualEntropyStr,Toast.LENGTH_LONG);
myToast.show();
addButtonClicked();
Intent returnToDiagram = new Intent(getBaseContext(), DiagramNew.class);
startActivity(returnToDiagram);
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(DataStateOne.this);
alert.setTitle("Error");
alert.setCancelable(false);
alert.setMessage("You did not fill all the required data.");
alert.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
alert.show();
}
}
});
mDeleteS1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
deleteButtonClicked();
}
});
}
public void printDatabase() {
String dbString = myDb.databaseToString();
Toast.makeText(getApplicationContext(), dbString, Toast.LENGTH_LONG).show();
}
public void addButtonClicked() {
Energies energies = new Energies(mS1ActualEnthalpy.getText().toString());
Energies energies2 = new Energies(mS1IdealEnthalpy.getText().toString());
Energies energies3 = new Energies(mS1ActualEntropy.getText().toString());
myDb.addEnergy(energies);
myDb.addEnergy(energies2);
myDb.addEnergy(energies3);
printDatabase();
}
public void deleteButtonClicked() {
String inputText = mS1ActualEnthalpy.getText().toString();
String inputText2 = mS1IdealEnthalpy.getText().toString();
String inputText3 = mS1ActualEntropy.getText().toString();
myDb.deleteEnergy(inputText);
myDb.deleteEnergy(inputText2);
myDb.deleteEnergy(inputText3);
}
public void updateProgress(){
int increase = myDb.increaseProgress(1);
}
}
答案 0 :(得分:0)
使用ensureCapacity()
并作为回报传递来自接收活动的意图以及进度条进度。当您收到进度时,只需更新进度条startActivityForResult