2011-12-24 60 views
0

在我的應用程序中有ListView和重置按鈕。 查看圖像獲取更多幫助 enter image description here 現在我想重置我輸入到ListView的值,並且應該點擊重置按鈕。如何重置ListView的值?

在我的那個活動我要去到像下面的數據添加到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方法顯示。 現在我應該怎麼做,如果我想重置點擊重置按鈕上的所有值?我是否應該完成並用新的呼叫進行該活動? 如何讓它成爲可能?

回答

2

我沒有看到你的適配器,我想你只是擴展ArrayAdapter。在這種情況下,您可以在其上調用方法clear()

+0

所以我必須調用重置按鈕上的clear()嗎?但我想只清除藍色值不是左邊的一個文本值然後??? – 2011-12-26 04:07:09

+0

感謝Anser。但是這樣做我清楚了所有的項目。而不是我想清除只有藍色顏色值被重置。我在其中添加該值的代碼在該問題中列出。 – 2011-12-26 04:18:23

+0

好吧,我得到了Sollution。非常感謝。 – 2011-12-26 04:26:12