2012-01-06 25 views
1

我已經做了ArrayList,並通過coading逐個添加它的值。我能看到整個ArrayList中像下面的代碼:如何爲下面的ArrayList創建Next和Previous Button代碼?

// 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; 

現在我想查看基於下一個和以前的按鈕,點擊一個接一個數組列表中的每個元素。

那麼,任何人都可以幫助我嗎?

我試着像下面的代碼:

對於Next按鈕點擊:

 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()); 
         } 
} 

而對於上一個按鈕clicke:

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。如何在查看數據時設置索引,而不是查看最後的位置。

那麼我的代碼有什麼錯? 請幫助我。 謝謝。

+0

你正在使用此代碼的故事嗎? – kosa 2012-01-06 04:47:01

回答

5

嘗試這樣的事情,你只需要增加ArrayList的位置來獲得下一個ArrayList記錄並減少位置以獲得前一個記錄。

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"); 
+0

那麼數據呢?我應該在哪裏顯示數據?在增量之前或增量之後?請把這些數據也寫一些代碼。謝謝。 – 2012-01-06 06:10:07

+0

好的。我來檢查一下。謝謝你的回覆。 – 2012-01-06 06:53:23

+0

好吧現在讓我試試這個' – 2012-01-06 07:07:53

相關問題