2016-09-04 5 views
0

私はsqliteデータでカスタムリストビューを持っています。リストビューには、3つのテキストビューと1つのチェックボックスが含まれています。私はリストビューでチェックされた項目の値で自分のsqliteデータベースを更新したい。ほとんどの手順を実行しましたが、2つの項目を選択して更新しようとすると、sqliteデータベースのレコードは1つだけ更新されます。選択したレコードを更新したいと思います。私のコードとScreenが与えられます。 保存ボタンクリックでこれを実行します。 sqliteから選択されたlistitems idがstr1変数に格納されています。あなたがif(chkConfirm.isChecked())をチェックする必要がアンドロイドのsqliteデータベースでチェックされたカスタムリストビューレコードを更新するには?

btnSaveCancellation.setOnClickListener(new OnClickListener() 
    {   
     @Override 
     public void onClick(View v) 
     {           
      long itemCount = listVCancelCollection.getCount(); 

      for(i=0;i<=itemCount-1;i++) 
      { 
       if(chkConfirm.isChecked()) 
       {     
        final long str1 = list_collection.get(i).getId();  

        AlertDialog.Builder alertDialogBuild=new AlertDialog.Builder(CancelCollection.this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); 
        alertDialogBuild.setTitle("Cancel Collection?"); 
        alertDialogBuild.setCancelable(false).setPositiveButton 
        ("Yes", new DialogInterface.OnClickListener() 
        { 
         @Override 
         public void onClick(DialogInterface dialog, int which) 
         { 
          dialog.cancel(); 

          displayReasonPopup();           
         } 

        private void displayReasonPopup() 
        { 
         Button btnAlert; 

         LayoutInflater layoutInflater = LayoutInflater.from(CancelCollection.this); 
         View promptView = layoutInflater.inflate(R.layout.input_dialog_reason, null); 

         final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CancelCollection.this); 
         alertDialogBuilder.setView(promptView); 
         alertDialogBuilder.setTitle("Reason"); 

         final EditText editReason = (EditText) promptView.findViewById(R.id.edittext_reason); 
         editReason.setTypeface(ttf);  

         alertDialogBuilder.setCancelable(false) 
         .setPositiveButton("Save", new DialogInterface.OnClickListener() 
         { 
          public void onClick(DialogInterface dialog, int id) 
          {         
           String edtString=editReason.getText().toString().trim(); 

           String strUpdate="UPDATE Customer_Collection SET Collection_Status = '0' , " 
              + "Cancel_Notes = '"+edtString+"'" 
              + "WHERE Customer_ID = '"+strCustomerID+"'" 
              + " AND Customer_Collection_ID = '"+str1+"'"; 

           SQLiteStatement statement = db.compileStatement(strUpdate); 
           db.beginTransaction(); 
           statement.execute(); 

           db.setTransactionSuccessful(); 
           db.endTransaction(); 

          } 
         }) 
          .setNegativeButton("Cancel", 
           new DialogInterface.OnClickListener() 
          { 
            public void onClick(DialogInterface dialog, int id) 
            { 
             dialog.cancel(); 
            } 
          }); 

         // create an alert dialog 
         final AlertDialog alertDD = alertDialogBuilder.create(); 
         alertDD.show(); 

         } 

         }).setNegativeButton("No", new DialogInterface.OnClickListener() 

         {        
          @Override 
          public void onClick(DialogInterface dialog, int which) 
          { 
           dialog.cancel(); 
          } 
         }); 

       AlertDialog alertDialog = alertDialogBuild.create(); 

       alertDialog = alertDialogBuild.setMessage("Do you want to cancel the selected collections?").show(); 
      } 

    } 
} 
}); 

答えて

0

は、私は多くのことを試してみましたが、これは私のリストビュー項目に属することができないあなたのListView項目

+0

に属しています。私のコードで何を変更すべきか教えてください。 –

関連する問題