2016-05-19 16 views
0

私はボタンをクリックして、アプリケーション内のすべての操作を削除して削除しています。削除ボタンをクリックすると、リストビューから削除されたアイテムがサーバーから削除されます。削除をクリックすると、すべてのリストビューが更新または更新されません。すべてのケースサーバーが削除されますが、リストビューは更新されません。私はnotifyDataSetChanged()method.How私はこの問題を解決することができます使用していますか? DeleteListのあなたは(onPostExecuteに対応するアダプタにnotifyDataSetChanged()を呼び出したいことがありnotifyDataSetChanged()メソッドがリストビューをリフレッシュしていません

public void alertMessage() 
      { 
       DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() 
       { 
        @Override 
        public void onClick(DialogInterface dialog, int which) 
        { 
         switch (which){ 
          //for cancel button 
          case DialogInterface.BUTTON_POSITIVE: 
           Category_Dashboard_Page activity = (Category_Dashboard_Page) context; 
           activity.swipeCategorylistView.closeAnimate(position); 

           break; 
          //for delete 
          case DialogInterface.BUTTON_NEGATIVE: 
           Category_Dashboard_Page activity1 = (Category_Dashboard_Page) context; 
           activity1.swipeCategorylistView.closeAnimate(position); 
           activity1.categoryList_items_obj.remove(position); 
           activity1.categoryAdapter.notifyDataSetChanged(); 
           new DeleteList().execute(); 
           break; 
          //for delete all 
          case DialogInterface.BUTTON_NEUTRAL: 
           Category_Dashboard_Page activity2 = (Category_Dashboard_Page) context; 
           activity2.swipeCategorylistView.closeAnimate(position); 

            for(int i=0;i<categoryList_items_obj.size();i++) 
            { 
             Category_Dashboard_Page.CategoryList_Item category_list_item = categoryList_items_obj.get(i); 
             System.out.println(category_list_item.getCategory_id()); 

             if(category_list_item.getCategory_id().equalsIgnoreCase("all")) 
             { 
              categoryList_items_obj.remove(i); 
             } 
            } 

           // notifyDataSetChanged(); 
           System.out.println(String.valueOf(getCount())); 
           System.out.println(String.valueOf(categoryList_items_obj.size())); 
           activity2.categoryAdapter.notifyDataSetChanged(); 
           new DeleteAllList().execute(); 
           break; 

         } 

        } 
       }; 
       AlertDialog.Builder builder = new AlertDialog.Builder(context); 
       builder.setTitle("Are you sure?"); 
       builder.setMessage("You want to delete this article from all categories.") 
         .setPositiveButton("Cancel ", dialogClickListener) 
         .setNegativeButton("Delete ", dialogClickListener) 
         .setNeutralButton("Delete all", dialogClickListener).show(); 

      } 
+0

代わりに 'notifyDataSetInvalidated()'を試してみてください。 –

+0

@ダニエルK私はこのnotifyDataSetInvalidated()同じ問題をもう一度試した –

+0

私は、新しいデータを受信し、アダプタを設定するメソッドを作成することをお勧めします。データが変更された後、適切な新しいデータでそのメソッドを呼び出します。 ** ALL **を削除している場合は –

答えて

0

)、あなたはAysncタスクを通じてリストから要素を削除しているので。これがあなたの問題を解決したかどうか教えてください。そうでない場合は、プロジェクトのコードをいくつか共有してください。

+0

http://paste.ubuntu.com/16503699/ –

+0

これを試してください:override onPostExecute( ) – hrushi

+0

@Override public void onPostExecute(文字列の結果){ Category_Dashboard_Pageアクティビティ=(Category_Dashboard_Page)コンテキスト; activity.categoryAdapter.notifyDataSetChanged(); } –

0

アダプターからもオブジェクトを除去する必要があります。次のコードを試してください。 -

public void alertMessage() 
      { 
       DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() 
       { 
        @Override 
        public void onClick(DialogInterface dialog, int which) 
        { 
         switch (which){ 
          //for cancel button 
          case DialogInterface.BUTTON_POSITIVE: 
           Category_Dashboard_Page activity = (Category_Dashboard_Page) context; 
           activity.swipeCategorylistView.closeAnimate(position); 

           break; 
          //for delete 
          case DialogInterface.BUTTON_NEGATIVE: 
           Category_Dashboard_Page activity1 = (Category_Dashboard_Page) context; 
           activity1.swipeCategorylistView.closeAnimate(position); 
           activity1.categoryList_items_obj.remove(position); 
           activity1.categoryAdapter.remove(position); 
           activity1.categoryAdapter.notifyDataSetChanged(); 
           new DeleteList().execute(); 
           break; 
          //for delete all 
          case DialogInterface.BUTTON_NEUTRAL: 
           Category_Dashboard_Page activity2 = (Category_Dashboard_Page) context; 
           activity2.swipeCategorylistView.closeAnimate(position); 

            for(int i=0;i<categoryList_items_obj.size();i++) 
            { 
             Category_Dashboard_Page.CategoryList_Item category_list_item = categoryList_items_obj.get(i); 
             System.out.println(category_list_item.getCategory_id()); 

             if(category_list_item.getCategory_id().equalsIgnoreCase("all")) 
             { 
              categoryList_items_obj.remove(i); 
              categoryAdapter.remove(i); 
             } 
            } 

           // notifyDataSetChanged(); 
           System.out.println(String.valueOf(getCount())); 
           System.out.println(String.valueOf(categoryList_items_obj.size())); 
           activity2.categoryAdapter.notifyDataSetChanged(); 
           new DeleteAllList().execute(); 
           break; 

         } 

        } 
       }; 
       AlertDialog.Builder builder = new AlertDialog.Builder(context); 
       builder.setTitle("Are you sure?"); 
       builder.setMessage("You want to delete this article from all categories.") 
         .setPositiveButton("Cancel ", dialogClickListener) 
         .setNegativeButton("Delete ", dialogClickListener) 
         .setNeutralButton("Delete all", dialogClickListener).show(); 

      } 
関連する問題