虽然在这个论坛上有很多这个问题的例子,但我仍然无法找到合适的地方开始新的活动。
继承我的代码:
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) {
}
}
我试图在任何地方实施新的屏幕活动,但仍然无法得到它。 任何有关建议应该去哪里的帮助都会非常感激。
感谢。
答案 0 :(得分:0)
我猜你想在onClick方法结束时更改活动。实际上,您希望在onClick方法的每个条件的末尾包含两个,一个。
在条件结束时,只需添加以下代码:
startActivity(new Intent(CurrentActivity.this, NewActivity.class));
CurrentActivity.this.finish();
另外,请确保将新活动添加到Manifest文件中:
<activity
android:name=".NewActivity"
android:label="@string/newActivityTitle" >
</activity>
一旦您的代码到达每个条件的末尾,如果新活动设置正确,则新活动应该接管。
分贝