Although there are numrous examples of this problem on this forum, I still cant find the appropriate place to start a new Activity.
Heres my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
final EditText milein = (EditText) findViewById(R.id.milein);
final EditText zipin = (EditText) findViewById(R.id.zipin);
final EditText mileout = (EditText) findViewById(R.id.mileout);
final EditText zipout = (EditText) findViewById(R.id.zipout);
final ToggleButton checkinbutton = (ToggleButton) findViewById(R.id.checkinbutton);
final Button submit = (Button) findViewById(R.id.submit);
/** Boolean for Sharedpreferences */
final SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean tgpref = preferences.getBoolean("tgpref", false);
checkinbutton.setChecked(tgpref);
/** ToggleButton Check-IN */
checkinbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkinbutton.isChecked()) {
milein.setVisibility(View.VISIBLE);
zipin.setVisibility(View.VISIBLE);
mileout.setVisibility(View.GONE);
zipout.setVisibility(View.GONE);
submit.setVisibility(View.VISIBLE);
SharedPreferences.Editor editor = preferences.edit();
/**
* <-- Boolean Preferences for Checkinbutton ToggleButton
* Checked
*/
editor.putBoolean("tgpref", true);
editor.commit();
} else {
milein.setVisibility(View.GONE);
zipin.setVisibility(View.GONE);
mileout.setVisibility(View.VISIBLE);
zipout.setVisibility(View.VISIBLE);
submit.setVisibility(View.VISIBLE);
SharedPreferences.Editor editor = preferences.edit();
/**
* <-- Boolean Preferences for Checkinbutton ToggleButton
* UnChecked
*/
editor.putBoolean("tgpref", false);
editor.commit();
/** AlertDialog Button Configurations */
final AlertDialog alertDialog = new AlertDialog.Builder(
screen1.this).create();
alertDialog.setMessage("Check-Out?");
alertDialog.setButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
alertDialog.setButton2("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
checkinbutton.setChecked(true);
milein.setVisibility(View.VISIBLE);
zipin.setVisibility(View.VISIBLE);
mileout.setVisibility(View.GONE);
zipout.setVisibility(View.GONE);
}
});
alertDialog.show();
}
};
});
}
public void onClick(View v) {
}
}
Ive tried to implement a new screen activity just about everywhere but still cant quite get it.
any help on suggesting where it should go would be MUCH appreciated.
Thanks.
I’m guessing you want to change activities at the end of your onClick methods. You’ll actually want to include two, one at the end of each conditional in your onClick method.
At the end of the condition, just add this code:
Also, make sure you add you new activity to your Manifest file:
Once your code gets to the end of each conditional, if the new activity is setup right, the new activity should take over.
db