我将数据显示在ListView中,如以下代码所示:

private class OrderAdapter extends ArrayAdapter<Employer> {

    private ArrayList<Employer> items;

    public OrderAdapter(Context context, int textViewResourceId, ArrayList<Employer> items) {
            super(context, textViewResourceId, items);
            this.items = items;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.paye_list_row, null);
            }
            Employer o = items.get(position);
            if (o != null) {
                    TextView tt = (TextView) v.findViewById(R.id.toptext);
                    TextView bt = (TextView) v.findViewById(R.id.value);

                    if (tt != null) {
                        tt.setText(o.getOrderName()); // Setting the Value here

                    }
                    if(bt != null){

                        if(position==0)
                           bt.setText(o.getTaxcode()); // Setting the Value here
                        if(position==1)
                            bt.setText(o.getPayPeriod()); // Setting the Value here
                        if(position==2)
                            bt.setText(o.getPayFrequency()); // Setting the Value here
                        if(position==3)
                            bt.setText(o.getSalaryWage()); // Setting the Value here
                        if(position==4)
                            bt.setText(o.getNetGrossAmount()); // Setting the Value here
                        if(position==5)
                            bt.setText(o.getKiwiSaverMember()); // Setting the Value here
                        if(position==6)
                            bt.setText(o.getEmployeeDeduction()); // Setting the Value here
                        if(position==7)
                            bt.setText(o.getEmployeeContribution()); // Setting the Value here
                        if(position==8)
                            bt.setText(o.getComplyingFundMember()); // Setting the Value here
                        if(position==9)
                            bt.setText(o.getFundContribution()); // Setting the Value here
                        if(position==10)
                            bt.setText(o.getESCTTaxRate()); // Setting the Value here
                        if(position==11)
                            bt.setText(o.getChildSupportDeduction()); // Setting the Value here
                        if(position==12)
                            bt.setText(o.getPayrollDonation()); // Setting the Value here

                    }
            }
            return v;
    }
}


我将数据手动添加到我的另一个ArrayList中,如下代码:

// Set Employee one by one
                ArrayList<Employer> tempEmployerList = employerList;
                System.out.println("=================================" +
                        "=IN end Document================================");
                System.out.println(" tempEmployerList Size:" +tempEmployerList.size());
                Employer m = new Employer();
                //  My Code for to add data
                m = new Employer();
                m.setTaxcode(taxCodeValue);
                m.setPayPeriod(payPeriodValue);
                m.setPayFrequency(payFrequencyValue);
                m.setSalaryWage(salaryWageValue);
                m.setNetGrossAmount("Gross");
                m.setKiwiSaverMember(kiwiSaverMemberValue);
                m.setEmployeeDeduction(employeeDeductionValue);
                m .setEmployeeContribution(employeeContributionValue);
                m.setComplyingFundMember(complyingFundMemberValue);
                m.setFundContribution(fundContributionValue);
                m.setESCTTaxRate(ESCTTaxRateValue);
                m.setChildSupportDeduction(childSupportDeductionValue);
                m.setPayrollDonation(payrollDonationValue);
                employerList.add(m);


如果我想在日志猫中显示该数据,则可以通过以下代码看到它:

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


一切正常。但是现在,如果我添加了更多的员工,那么我想在单击下一步按钮时将其一一显示在列表视图中。

那么怎么可能。
请帮我。
谢谢。

最佳答案

在下一个和上一个按钮事件将Employer对象更改为列表中的下一个或上一个项目的情况下,将一个Employee对象声明为Activity中的一个字段,并从该字段加载您的适配器数据,并调用adapter.notifyDataSetChanged()方法。

09-04 02:13
查看更多