如何重置ListView的值?

时间:2011-12-24 07:35:13

标签: android listview android-layout arraylist android-listview

在我的应用程序中有ListView和重置按钮。 有关更多帮助,请参见图像 enter image description here 现在我想将我输入的值重置为ListView,并且应该点击重置按钮。

在我的那个Activity中,我将把数据添加到该ListView中,如下所示:

    m_orders = new ArrayList<Order>();
                    payListForEmployee = new String[] {"Tax Code","Pay period Begin","Pay Frequency","Salary/Wage per pay",
                        "Net or Gross Amount","KS Employee deduction","KS Employee contributions","Child Support deduction","Payroll giving donation"};

                    Order o[]=new Order[payListForEmployee.length];
                    System.out.println("The Length is: "+payListForEmployee.length);
                    for (int i = 0; i < payListForEmployee.length; i++) 
                    {
                        o[i]=new Order();
                        o[i].setOrderName(payListForEmployee[i]);

                        //myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
                        // for TAXCODE
                        if(i==0) {
                            taxCodeValue = PAYEEmployeeDetail.taxCodeFinalValue;
                            if((taxCodeValue==null)) {
                                taxCodeValue = "Please select";
                            }
                            o[i].setOrderStatus(taxCodeValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());

                        }
                        // for Pay Period Frequency
                        if(i==1) {
                            //payPeriodValue = myPrefs.getString("payperiod", "12 09 2011");
                            payPeriodValue =  PAYEEmployeeDetail.payPeriodFinalValue;
                            if((payPeriodValue==null)) {
                                payPeriodValue = "--/--/----";
                            }
                            o[i].setOrderStatus(payPeriodValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // for Pay frequency
                        if(i==2) {
                            //payFrequencyValue = myPrefs.getString("payfrequency", "Weekly");
                            payFrequencyValue =  PAYEEmployeeDetail.payFrequencyFinalValue;
                            if((payFrequencyValue==null)) {
                                payFrequencyValue = "Please select";
                            }
                            o[i].setOrderStatus(payFrequencyValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // for salary / wage
                        if(i==3) {
                            salaryWageValue =  PAYEEmployeeDetail.salaryWageFinalValue;
                            if((salaryWageValue==null)||(salaryWageValue.equals(""))) {
                                salaryWageValue = "$0";
                            }
                            else{
                                salaryWageValue = "$"+salaryWageValue;
                            }
                            o[i].setOrderStatus(salaryWageValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // For Gross / Net
                        if(i==4) {

                            o[i].setOrderStatus("Gross");
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // for KS Employee Deduction
                        if(i==5) {
                            employeeDeductionValue =  PAYEEmployeeDetail.employeeDeductionFinalValue;
                            if((employeeDeductionValue==null)||(employeeDeductionValue.equals(""))) {
                                employeeDeductionValue = "0%";
                            }
                            o[i].setOrderStatus(employeeDeductionValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // for KS Employee Contribution
                        if(i==6) {
                            employeeContributionValue =  PAYEEmployeeDetail.employeeContributionFinalValue;
                            if((employeeContributionValue==null)||(employeeContributionValue.equals(""))) {
                                employeeContributionValue = "0%";
                            }
                            else{
                                employeeContributionValue = employeeContributionValue+"%";
                            }
                            o[i].setOrderStatus(employeeContributionValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // for Child Support Deduction
                        if(i==7) {
                            childSupportDeductionValue =  PAYEEmployeeDetail.childSupportDeductionFinalValue;
                            if((childSupportDeductionValue==null)||(childSupportDeductionValue.equals(""))) {
                                childSupportDeductionValue = "$0";
                            }
                            else{
                                childSupportDeductionValue = "$"+childSupportDeductionValue;
                            }
                            o[i].setOrderStatus(childSupportDeductionValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        // for Payroll giving donation
                        if(i==8) {
                            payrollDonationValue =  PAYEEmployeeDetail.payrollDonationFinalValue;
                            if((payrollDonationValue==null)||(payrollDonationValue.equals(""))) {
                                payrollDonationValue = "$0";
                            }
                            else{
                                payrollDonationValue = "$"+payrollDonationValue;
                            }
                            o[i].setOrderStatus(payrollDonationValue);
                            //System.out.println("The Value is: "+o[i].getOrderStatus());
                        }
                        m_orders.add(o[i]);
}

它是getView方法显示的。 现在如果我想重置点击重置按钮的所有值,我该怎么办?我是否必须完成并使用新活动调用该活动? 如何使它成为可能?

1 个答案:

答案 0 :(得分:2)

我没有看到你的适配器,我想你只是在扩展ArrayAdapter。在这种情况下,您只需调用方法clear()即可。