如何使下面的ArrayList的下一个和上一个按钮代码? [英] How to make the Next and Previous Button code for the below ArrayList?
问题描述
我制作了ArrayList,并通过编码将值一一加到其中.我可以看到整个arrayList像下面的代码一样:
I have made the ArrayList and addind the value one by one in it by the coading. I can able to see that whole arrayList as like below code:
// 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;
现在,我想基于下一个和上一个按钮的单击,逐个查看该数组的每个元素.
Now i want to view that every element of that array list on the one by one based on the next and previous button click.
那么有人可以帮我吗?
我已经尝试过以下代码:
I have try it like below code:
对于nextButton,请单击:
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设置相同的内容.在查看数据时而不是在最后位置时如何设置索引.
Edited
I also want to Set the same for the delete functionality and for addindg the new data to that ArrayList. How to set the index while i am viewing the data and not at the last position.
那么我的代码有什么问题呢? 请帮我. 谢谢.
So whats wrong in my code ? Please help me for that. Thanks.
推荐答案
尝试类似的方法,您只需要增加ArrayList的位置来获取下一个ArrayList记录,并减少该位置以获取前一个Record.
Try something like this, you just need to increment the ArrayList position to get the next ArrayList Record and decrement the position to get the previous Record.
int position = 0;
下一步按钮:
if(position < tempEmployerList.size() - 1){
position++;
tempEmployerList.get(position);
// show the data here
}
else
Log.d("TAG","Reached Last Record");
上一个按钮:
if(position > 0){
position--;
tempEmployerList.get(position);
// show the data here
}
else
Log.d("TAG","Reach First Record");
这篇关于如何使下面的ArrayList的下一个和上一个按钮代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!