0

내 첫 번째 문제는 내 액티비티에서 내 어댑터에 Amount를 전달하여 어댑터에서 텍스트 편집 값을 설정했지만 표시하지 않는 것입니다. 두 번째 문제는 내 어댑터 내에서 내 편집 텍스트의 값을 변경하면 목록보기를 스크롤 할 때 값이 손실된다는 것입니다. 어댑터EditText는 어댑터 호출시 값을 표시하지 않으며 EditText는 listView가 스크롤 될 때 값을 잃습니다.

다음

내 코드 :

public class CustomListView_InvoiceList extends BaseAdapter { 

private Context mContext; 
private List<InvoiceList> invoiceLists; 
private float TotalPaymentAmount; 

public CustomListView_InvoiceList(Context mContext, List<InvoiceList> invoiceLists, Float totalPaymentAmount) { 
    this.mContext = mContext; 
    this.invoiceLists = invoiceLists; 
    this.TotalPaymentAmount = totalPaymentAmount; 
} 

public static class ViewHolder { 
    CheckBox SelectInvoiceCB, PayFull, PayPartial; 
    TextView SalesInvoiceNo, InvoiceDate, InvoiceAmount, AmountDue, DueDate, CreditMemoID, CreditMemoDate, CreditMemoReason; 
    LinearLayout LL2, LL3; 
    EditText TotalAmount; 
    ImageView CaptureForm; 
} 

@Override 
public View getView(final int position, View view, ViewGroup viewGroup) { 
    //View v = View.inflate(mContext, R.layout.sales_invoice_custom,null); 
    final ViewHolder holder; 

    if (view == null) { 
     view = View.inflate(mContext, R.layout.sales_invoice_custom, null); 
     holder = new ViewHolder(); 

     holder.SelectInvoiceCB = (CheckBox) view.findViewById(R.id.selectInvoiceCB); 
     holder.SalesInvoiceNo = (TextView) view.findViewById(R.id.SINo); 
     holder.InvoiceDate = (TextView) view.findViewById(R.id.SIDate); 
     holder.InvoiceAmount = (TextView) view.findViewById(R.id.SIAmount); 
     holder.AmountDue = (TextView) view.findViewById(R.id.SIAmountDue); 
     holder.DueDate = (TextView) view.findViewById(R.id.SIdueDate); 
     holder.PayFull = (CheckBox) view.findViewById(R.id.SIFull); 
     holder.PayPartial = (CheckBox) view.findViewById(R.id.SIPartial); 
     holder.TotalAmount = (EditText) view.findViewById(R.id.SITotalAmount); 
     holder.CreditMemoID = (TextView) view.findViewById(R.id.creditMemoID); 
     holder.CreditMemoDate = (TextView) view.findViewById(R.id.creditMemoDate); 
     holder.CreditMemoReason = (TextView) view.findViewById(R.id.creditMemoReason); 
     holder.LL2 = (LinearLayout) view.findViewById(R.id.ll2); 
     holder.LL3 = (LinearLayout) view.findViewById(R.id.ll3); 

     holder.SelectInvoiceCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       int getPosition = (Integer) buttonView.getTag(); // Here we get the position that we have set for the checkbox using setTag. 
       invoiceLists.get(getPosition).setSelectInvoice(buttonView.isChecked()); // Set the value of checkbox to maintain its state. 
      } 
     }); 

     holder.PayFull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       int getPosition = (Integer) buttonView.getTag(); // Here we get the position that we have set for the checkbox using setTag. 
       invoiceLists.get(getPosition).setPayFull(buttonView.isChecked()); // Set the value of checkbox to maintain its state. 
       if (holder.PayFull.isChecked()) { 
        holder.PayPartial.setChecked(false); 
       } 
      } 
     }); 

     holder.PayPartial.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       int getPosition = (Integer) buttonView.getTag(); // Here we get the position that we have set for the checkbox using setTag. 
       invoiceLists.get(getPosition).setPayPartial(buttonView.isChecked()); // Set the value of checkbox to maintain its state. 
       if (holder.PayPartial.isChecked()) { 
        holder.PayFull.setChecked(false); 
       } 
      } 
     }); 

     view.setTag(holder); 
     view.setTag(R.id.SITotalAmount, holder.TotalAmount); 
     view.setTag(R.id.selectInvoiceCB, holder.SelectInvoiceCB); 
     view.setTag(R.id.SIFull, holder.PayFull); 
     view.setTag(R.id.SIPartial, holder.PayPartial); 
    } else { 
     holder = (ViewHolder) view.getTag(); 
    } 

    InvoicePopulate(view,holder, position); 

    return view; 
} 

public void InvoicePopulate(final View view, final ViewHolder holder, final int position) { 
    dbHelper = new DBHelper(mContext); 

    Calendar c = Calendar.getInstance(); 
    SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd"); 
    final String formattedDate = df1.format(c.getTime()); 

    try { 
     dbHelper.openDataBase(); 

     // LAYOUT VISIBILITY FOR CREDIT MEMOs 
     try { 
      if (invoiceLists.get(position).getCredit_Memo_ID().equals(null) || invoiceLists.get(position).getCredit_Memo_ID().isEmpty() 
        || invoiceLists.get(position).getCredit_Memo_ID().length() < 1 
        || invoiceLists.get(position).getCredit_Memo_ID().trim().equals("")){ 
       holder.CreditMemoID.setVisibility(View.GONE); 
       holder.CreditMemoDate.setVisibility(View.GONE); 
       holder.CreditMemoReason.setVisibility(View.GONE); 
       holder.LL2.setVisibility(View.GONE); 
       holder.LL3.setVisibility(View.GONE); 
      } else { 
       holder.LL2.setVisibility(View.VISIBLE); 
       holder.LL3.setVisibility(View.VISIBLE); 
       holder.CreditMemoID.setVisibility(View.VISIBLE); 
       holder.CreditMemoDate.setVisibility(View.VISIBLE); 
       holder.CreditMemoReason.setVisibility(View.VISIBLE); 

       holder.CreditMemoID.setText(invoiceLists.get(position).getCredit_Memo_ID()); 
       holder.CreditMemoDate.setText(invoiceLists.get(position).getCredit_Memo_Date().substring(0,10)); 
       holder.CreditMemoReason.setText(invoiceLists.get(position).getCredit_Memo_Reason()); 
      } 
     } catch (Exception e) { 
      e.getMessage(); 
     } 

     holder.SalesInvoiceNo.setText(invoiceLists.get(position).getSales_Invoice_ID()); 
     holder.InvoiceDate.setText(invoiceLists.get(position).getInvoice_Date()); 
     holder.DueDate.setText(invoiceLists.get(position).getDue_Date()); 

     float invAmount = 0; 
     invAmount = Math.round(Float.parseFloat(invoiceLists.get(position).getInvoice_Amount())*100.00)/(float)100.00; 
     holder.InvoiceAmount.setText(String.format("%,.2f",invAmount)); 
     holder.AmountDue.setText(String.format("%,.2f",invAmount)); 
     //holder.InvoiceAmount.setText(invoiceLists.get(position).getInvoice_Amount()); 

     holder.TotalAmount.setTag(position); 
     holder.SelectInvoiceCB.setTag(position); // This line is important. 
     holder.PayFull.setTag(position); // This line is important. 
     holder.PayPartial.setTag(position); // This line is important. 


     holder.TotalAmount.setText(invoiceLists.get(position).getAmount_Paid()); 
     holder.SelectInvoiceCB.setChecked(invoiceLists.get(position).isSelectInvoice()); 
     holder.PayFull.setChecked(invoiceLists.get(position).isPayFull()); 
     holder.PayPartial.setChecked(invoiceLists.get(position).isPayPartial()); 

     try { 
      if (invoiceLists.get(position).getAmount_Paid().toString().equals("") || 
        invoiceLists.get(position).getAmount_Paid().toString().equals("0.0") || 
        Float.parseFloat(invoiceLists.get(position).getAmount_Paid().toString()) < 1) { 
       invAmount = 0; 
       invAmountDue = 0; 
       invAmountPaid = 0; 
       //invAmount = Float.parseFloat(invoiceLists.get(position).getInvoice_Amount()); 
       invAmount = Math.round(Float.parseFloat(invoiceLists.get(position).getInvoice_Amount())*100.00)/(float)100.00; 
       invAmountDue = invAmount - invAmountPaid; 
       Log.e("Without AmountPaid ", "Amount Due : " + String.valueOf(invAmountDue)); 
      } else { 
       invAmount = 0; 
       invAmountDue = 0; 
       invAmountPaid = Math.round(Float.parseFloat(invoiceLists.get(position).getAmount_Paid())*100.00)/(float)100.00; 
       //invAmount = Float.parseFloat(invoiceLists.get(position).getInvoice_Amount()); 
       invAmount = Math.round(Float.parseFloat(invoiceLists.get(position).getInvoice_Amount())*100.00)/(float)100.00; 
       invAmountDue = invAmount - invAmountPaid; 
       Log.e("With AmountPaid ", "Amount Due : " + String.valueOf(invAmountDue)); 
      } 

      holder.AmountDue.setText(String.format("%,.2f",invAmountDue)); 
      //holder.InvoiceAmount.setText(invoiceLists.get(position).getInvoice_Amount()); 
     } catch (Exception e) { 
      e.getMessage(); 
     } 

     /*final float finalInvAmount = invAmountDue; 
     holder.PayFull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       if (holder.PayFull.isChecked()) { 
        holder.PayPartial.setChecked(false); 
        if (holder.SelectInvoiceCB.isChecked()) { 
         invoiceStatusValue = "PAID_FULL"; 
         holder.TotalAmount.setText(String.valueOf(Math.round(finalInvAmount*100.00)/100.00)); 
         //holder.TotalAmount.setText(holder.InvoiceAmount.getText().toString()); 
        } 
       } 
      } 
     }); 

     holder.PayPartial.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       if (holder.PayPartial.isChecked()) { 
        holder.PayFull.setChecked(false); 
        if (holder.SelectInvoiceCB.isChecked()) { 
         invoiceStatusValue = "PAID_PARTIAL"; 
         holder.TotalAmount.setText("0.00"); 
        } 
       } 
      } 
     });*/ 

     if (TotalPaymentAmount >= Float.parseFloat(String.valueOf(invAmountDue))) { 
      holder.SelectInvoiceCB.setChecked(true); 
      holder.PayFull.setChecked(true); 
      holder.PayFull.setClickable(true); 
      holder.PayPartial.setClickable(true); 

      holder.TotalAmount.setText(String.valueOf(Math.round(invAmountDue * 100.00)/100.00)); 

      System.out.println("TotalPaymentAmount: " + TotalPaymentAmount); 
      System.out.println("invAmountDue: " + invAmountDue); 

      if (Float.parseFloat(String.valueOf(invAmountDue)) < 1) { 
       Log.e("Computations : ", TotalPaymentAmount + " + " + String.valueOf(Float.parseFloat(String.valueOf(invAmountDue)))); 
       Log.e("Equals ", "TotalPaymentAmount = " + TotalPaymentAmount); 
      } else { 
       TotalPaymentAmount = TotalPaymentAmount - Float.parseFloat(String.valueOf(invAmountDue)); 
      } 
     } else { 
      if (TotalPaymentAmount < 1) { 
       holder.TotalAmount.setText("0.00"); 
       /*holder.PayFull.setClickable(false); 
       holder.PayPartial.setClickable(false);*/ 

      } else { 
       holder.SelectInvoiceCB.setChecked(true); 
       holder.PayPartial.setChecked(true); 
       holder.PayFull.setClickable(true); 
       holder.PayPartial.setClickable(true); 
       holder.TotalAmount.setText(String.valueOf(Math.round(TotalPaymentAmount * 100.00)/100.00)); 

       if ((TotalPaymentAmount - Float.parseFloat(String.valueOf(invAmountDue))) < 0) { 
        TotalPaymentAmount = (float) 0.0; 
       } else { 
        TotalPaymentAmount = TotalPaymentAmount - Float.parseFloat(String.valueOf(invAmountDue)); 
       } 
      } 
     } 

    } catch (Exception e) { 
     e.getMessage(); 
     System.out.println("Custom Invoice List: " + e); 
    } finally { 
     dbHelper.close(); 
    } 

} 
+0

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyItemChanged(int) –

답변

0

첫째, 대신 ListView에의 RecyclerView를 사용하는 것이 좋습니다는, 간단한 구현은 스크롤의 문제를 방지 할 수 있습니다. 내가이 링크 추천 :
https://developer.android.com/training/material/lists-cards.html https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

둘째, *는 SQLite 데이터베이스를 뷰가 생성 될 때마다 여는 방법 invoicePopulate을 스크롤로보기는 다시 때문에 이것은 심각한 성능 문제를 제공하고 여러 생성 인스턴스가 끝나면 오류가 발생하여 데이터베이스에 액세스 할 수 없습니다. 이를 위해 이전에 데이터를 계산하여 이미 준비된 어댑터에 전달하는 것이 좋습니다.

어댑터를 사용하여 정보를 표시하는 것이 가장 좋습니다. 정보를 표시하려면 이전에 시도해보십시오.