这是第一个屏幕的代码,我已经使用了两个屏幕的所有import语句。我有一个条件语句,检查editText Box或ratingBar是否为空。
public class BasicDetails extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic_details_screen);
TextView textClass = (TextView)findViewById(R.id.textClass);
TextView textSchool = (TextView)findViewById(R.id.textSchool);
TextView textPhoto = (TextView)findViewById(R.id.textPhoto);
TextView textabtYear = (TextView)findViewById(R.id.textabtYear);
final EditText editClass = (EditText)findViewById(R.id.editClass);
final EditText editSchool = (EditText)findViewById(R.id.editSchool);
final EditText abtyear = (EditText)findViewById(R.id.abtYear);
//Button buttonPhoto = (Button)findViewById(R.id.buttonPhoto);
Button buttonBnext = (Button)findViewById(R.id.buttonBnext);
buttonBnext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Performs action on click
if ((editClass.getText().length() != 0) && (editSchool.getText().length() != 0) && (abtyear.getText().length() != 0)) {
Intent intent = new Intent(BasicDetails.this, PortfolioDetails.class);
startActivity(intent);
//opens the portfolio details class
} else {
Toast.makeText(BasicDetails.this, "Please enter all the details!!!", Toast.LENGTH_LONG).show();
}
}
});
}
}
这是下一个屏幕的代码。所以基本上有一个意图会将你从一个屏幕带到另一个屏幕,但我在我的模拟器上收到一条错误消息"我的应用程序(或GoPort)不幸停止工作"
public class PortfolioDetails extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.porfolio_details_screen);
TextView textAchievements = (TextView)findViewById(R.id.textAchievements);
TextView textProgress = (TextView)findViewById(R.id.textProgress);
TextView textFeedback = (TextView)findViewById(R.id.textFeedback);
final EditText editAchievements = (EditText)findViewById(R.id.editAchievements);
final EditText editFeedback = (EditText)findViewById(R.id.editFeedback);
final RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar);
Button buttonCnext = (Button)findViewById(R.id.buttonCNext);
buttonCnext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Performs action on click
if ((editAchievements.getText().length() != 0) && (editFeedback.getText().length() != 0)) {
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// place intent for new activity
Intent intent = new Intent(PortfolioDetails.this, SlamDetails.class);
startActivity(intent);
//opens the portfolio details class
}
});
} else {
Toast.makeText(PortfolioDetails.this, "Please enter all the details!!!", Toast.LENGTH_LONG).show();
}
}
});
}
}