我在名为“选择”的活动中有两个按钮“雇员”和“雇主”,如果按下“雇员”按钮,则应禁用“主页”活动中的两个按钮“addEmployee”和“generateReport”。
选拔活动
public class Selection extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selection);
final Button btn_Employee = (Button) findViewById(R.id.btn_Employee);
Button btn_Employer = (Button) findViewById(R.id.btn_Employer);
btn_Employee.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vEmployee) {
if(btn_Employee.isPressed())
{
//markAttendance and generateReport button should be disabled
Intent i = new Intent(Selection.this, HomeActivity.class);
startActivity(i);
}
}
});
btn_Employer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vEmployer) {
}
});
}
}
家庭活动
public class HomeActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ImageButton markAttendance = (ImageButton) findViewById(R.id.markAttendance);
ImageButton viewHolidays = (ImageButton) findViewById(R.id.viewHolidays);
ImageButton addEmployee = (ImageButton) findViewById(R.id.addEmployee);
ImageButton generateReport = (ImageButton) findViewById(R.id.generateReport);
Toolbar toolbar = (Toolbar) findViewById(R.id.sign_in_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getTitle());
markAttendance.setOnClickListener(this);
viewHolidays.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holidays();
}
});
addEmployee.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddEmployee();
}
});
generateReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
report();
}
});
}
private void AddEmployee() {
Intent addIntent = new Intent(this, EmployeeDetails.class);
startActivity(addIntent);
}
private void report() {
Intent webIntent = new Intent(this, TempWeb.class);
startActivity(webIntent);
}
private void holidays() {
Intent holidayIntent = new Intent(this, Holiday.class);
startActivity(holidayIntent);
}
@Override
public void onClick(View v) {
attendance();
}
private void attendance() {
Intent attendanceIntent = new Intent(this, MarkAttendance.class);
startActivity(attendanceIntent);
}
}
任何帮助表示赞赏!
您可以通过通过您的 Intent 传递一些数据来实现,这些数据可以识别在 中Home Acitivity
,按下了哪个按钮Selection Activity
。
在按下员工按钮的选择活动中:
Intent i = new Intent(Selection.this, HomeActivity.class);
intent.putExtra("IS_EMPLOYEE", true);
startActivity(i);
在 Home Activity 中检查是否按下了员工按钮,并执行相应的操作:
if(getIntent().getExtras().getBoolean("IS_EMPLOYEE")){
// do what you want to do on employee button press.
}
else{
// do what you want to do on employer button press.
}
false
当Selection Activity
,雇主按钮被按下时,也通过意图传递值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句