Я создал ArrayList и добавил значение одно за другим в кодировку.Я могу видеть весь массив arrayList, как показано ниже:
// TO DISPLAY DATA
for(int j=0;j<tempEmployerList.size();j++)
{
System.out.println("================ Employee: "+(j+1)+"======================");
m = new Employer();
m=tempEmployerList.get(j);
//System.out.println("TaxCodeHeading: "+(j+1)+" = "+m.getOrderName());
System.out.println("TaxCode: "+(j+1)+" = "+m.getTaxcode());
System.out.println("PayPeriod: "+(j+1)+" = "+m.getPayPeriod());
System.out.println("Frequency: "+(j+1)+" = "+m.getPayFrequency());
System.out.println("Salary/Wage: "+(j+1)+" = "+m.getSalaryWage());
System.out.println("NetGross Amount: "+(j+1)+" = "+m.getNetGrossAmount());
System.out.println("KiwiSaverMember: "+(j+1)+" = "+m.getKiwiSaverMember());
System.out.println("Employee Deduction: "+(j+1)+" = "+m.getEmployeeDeduction());
System.out.println("Complying Fund Member: "+(j+1)+" = "+m.getComplyingFundMember());
System.out.println("Fund Contribution: "+(j+1)+" = "+m.getFundContribution());
System.out.println("ESCT Tax Rate: "+(j+1)+" = "+m.getESCTTaxRate());
System.out.println("Child Support Deduction: "+(j+1)+" = "+m.getChildSupportDeduction());
System.out.println("Payroll giving Donation: "+(j+1)+" = "+m.getPayrollDonation());
}
TOTAL_EMPLOYEE=tempEmployerList.size();
empIndex = TOTAL_EMPLOYEE;
Теперь я хочу увидеть, что каждый элемент этого массива перечисляется по одному на основе следующего и предыдущего нажатия кнопки.
Так может ли кто-нибудь помочь мне в этом?
Я попробую это, как показано ниже:
Для нажатия следующей кнопки:
Toast.makeText(getApplicationContext(), "Index is:"+empIndex, Toast.LENGTH_SHORT).show();
System.out.println("The Employer Size is: "+tempEmployerList.size());
if((empIndex)==TOTAL_EMPLOYEE){
Toast.makeText(getApplicationContext(), "There are no any Employee", Toast.LENGTH_SHORT).show();
}else{
if(empIndex == 0){
empIndex = empIndex+1;
}
empIndex = empIndex+1;
if(empIndex==TOTAL_EMPLOYEE){
Toast.makeText(getApplicationContext(), "There are no any Employee", Toast.LENGTH_SHORT).show();
}else{
System.out.println("the Index IS::::" +empIndex);
headerText.setText("Emp "+(empIndex));
//empIndex = empIndex + 1;
Employer m = new Employer();
int j = empIndex-1;
m=tempEmployerList.get(j);
//System.out.println("TaxCodeHeading: "+(j+1)+" = "+m.getOrderName());
System.out.println("TaxCode: "+(j)+" = "+m.getTaxcode());
System.out.println("PayPeriod: "+(j)+" = "+m.getPayPeriod());
System.out.println("Frequency: "+(j)+" = "+m.getPayFrequency());
System.out.println("Salary/Wage: "+(j)+" = "+m.getSalaryWage());
System.out.println("NetGross Amount: "+(j)+" = "+m.getNetGrossAmount());
System.out.println("KiwiSaverMember: "+(j)+" = "+m.getKiwiSaverMember());
System.out.println("Employee Deduction: "+(j)+" = "+m.getEmployeeDeduction());
System.out.println("Complying Fund Member: "+(j)+" = "+m.getComplyingFundMember());
System.out.println("Fund Contribution: "+(j)+" = "+m.getFundContribution());
System.out.println("ESCT Tax Rate: "+(j)+" = "+m.getESCTTaxRate());
System.out.println("Child Support Deduction: "+(j)+" = "+m.getChildSupportDeduction());
System.out.println("Payroll giving Donation: "+(j)+" = "+m.getPayrollDonation());
}
}
И для предыдущего нажатия кнопки:
case R.id.backButton:
System.out.println("Total Employee is: "+TOTAL_EMPLOYEE);
Toast.makeText(getApplicationContext(), "Index is:"+empIndex, Toast.LENGTH_SHORT).show();
if(empIndex == 0){
PAYEEmployerDetail.taxCodeFinalValue=null;
PAYEEmployerDetail.payPeriodFinalValue=null;
PAYEEmployerDetail.salaryWageFinalValue=null;
PAYEEmployerDetail.payFrequencyFinalValue=null;
PAYEEmployerDetail.employeeDeductionFinalValue=null;
PAYEEmployerDetail.employeeContributionFinalValue=null;
PAYEEmployerDetail.childSupportDeductionFinalValue=null;
PAYEEmployerDetail.payrollDonationFinalValue=null;
PAYEEmployerDetail.kiwiSaverMemberFinalValue=null;
PAYEEmployerDetail.complyingFundMemberFinalValue=null;
PAYEEmployerDetail.fundContributionFinalValue=null;
PAYEEmployerDetail.ESCTTaxRateFinalValue=null;
TOTAL_EMPLOYEE = 0;
empIndex = 0;
tempEmployerList = null;
employerList = null;
finish();
}else{
if(empIndex>TOTAL_EMPLOYEE)
empIndex = empIndex - (empIndex - TOTAL_EMPLOYEE);
empIndex = empIndex -1;
System.out.println("the Index IS :" +empIndex);
headerText.setText("Emp "+(empIndex+1));
Employer m = new Employer();
int j=empIndex;
m=tempEmployerList.get(j);
//System.out.println("TaxCodeHeading: "+(j+1)+" = "+m.getOrderName());
System.out.println("TaxCode: "+(j)+" = "+m.getTaxcode());
System.out.println("PayPeriod: "+(j)+" = "+m.getPayPeriod());
System.out.println("Frequency: "+(j)+" = "+m.getPayFrequency());
System.out.println("Salary/Wage: "+(j)+" = "+m.getSalaryWage());
System.out.println("NetGross Amount: "+(j)+" = "+m.getNetGrossAmount());
System.out.println("KiwiSaverMember: "+(j)+" = "+m.getKiwiSaverMember());
System.out.println("Employee Deduction: "+(j)+" = "+m.getEmployeeDeduction());
System.out.println("Complying Fund Member: "+(j)+" = "+m.getComplyingFundMember());
System.out.println("Fund Contribution: "+(j)+" = "+m.getFundContribution());
System.out.println("ESCT Tax Rate: "+(j)+" = "+m.getESCTTaxRate());
System.out.println("Child Support Deduction: "+(j)+" = "+m.getChildSupportDeduction());
System.out.println("Payroll giving Donation: "+(j)+" = "+m.getPayrollDonation());
}
}
Отредактировано
Я также хочу установить то же самое для функции удаления и для добавления новых данных втот ArrayList.Как установить индекс при просмотре данных, а не в последней позиции.
Так что же не так в моем коде?Пожалуйста, помогите мне за это.Спасибо.