2016-04-20 19 views
0

Ich bevölkere List<Object> Daten, die von Local DB abgerufen wird. Es ist gut in der Anfangszeit bevölkert. Ich habe hier 13 Tabs. Abhängig von der Kategorie Ich bevölkere Produkte.Anonymer Fehler in RecyclerView

Ich bin auf dem Weg nach rechts wie Bäckerei --> Schüssel --> Box --> Tassen ===> Alles ist in Ordnung.
(Ähnliches Bild 1)

Aber als ich in Richtung Bäckerei <-- Bowl <-- Box <-- Cups Swipe ==> alle Daten ein.
(Ähnliches Bild 2)

Aber in LogCat druckt er die richtigen Daten.

Image 1

================================

Image 2

Die Codierung lautet hier:

TabFragmentSearch newInstance-Wert ist eine Rückgabe von MainActivity.

public static TabFragmentSearch newInstance(int categoryId, String categoryName) { 

    Bundle args = new Bundle(); 
    args.putInt(CommonUtil.CATEGORY_ID, categoryId); 
    args.putString(CommonUtil.CATEGORY_NAME, categoryName); 

    Log.e("TabFragmnet Instance", categoryId + " " + categoryName); 

    TabFragmentSearch fragment = new TabFragmentSearch(); 
    fragment.setArguments(args); 
    return fragment; 
} 

======================= 

public void onViewCreated(View view, Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 
     config = new Config(getActivity()); 
     context = getActivity(); 
     CommonUtil.pref = context.getSharedPreferences(CommonUtil.MyPREFERENCES, Context.MODE_PRIVATE); 

     commonUtil.dbUtil = new DbUtil(context); 
     commonUtil.dbUtil.open(); 
     commonUtil.dbHelper = new DbHelper(context); 

     recyclerView = (RecyclerView) view.findViewById(R.id.fragment_list_rv); 
     edtSearch = (SearchView) view.findViewById(R.id.edtSearch); 
     noData = (TextView) view.findViewById(R.id.noData); 
     noData.setVisibility(View.GONE); 
     recyclerView.setVisibility(View.VISIBLE); 

     mLayoutManager = new GridLayoutManager(context, 2); 
     recyclerView.setLayoutManager(mLayoutManager); 
     recyclerView.setHasFixedSize(true); 

     RestaurantDataSet = new ArrayList<>(); 

     swipeCheck = false; 

     cartRestaurant = new ArrayList<>(); 
     RestaurantDataSet = MainActivity.cartRestaurant; 

     int BeanCatId = getArguments().getInt(CommonUtil.CATEGORY_ID); 

     Config.startFilterClicked = false; 
     SharedPreferences.Editor editor1 = CommonUtil.pref.edit(); 
     editor1.putBoolean("startFilter", Config.startFilterClicked); 
     editor1.commit(); 

     Cursor curCAT_PDT = commonUtil.dbUtil.getCAT_PDT(String.valueOf(BeanCatId)); 

     if (curCAT_PDT != null && curCAT_PDT.getCount() > 0) { 
      curCAT_PDT.moveToFirst(); 
      int i = 0; 
      do { 
       cartRestaurant.add(new CartRes(curCAT_PDT.getInt(curCAT_PDT.getColumnIndex(DbHelper.JSON_CATEGORY_ID)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_CATEGORY_NAME)), 
         curCAT_PDT.getInt(curCAT_PDT.getColumnIndex(DbHelper.JSON_PRODUCT_ID)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_PRODUCT_NAME)), 
         curCAT_PDT.getInt(curCAT_PDT.getColumnIndex(DbHelper.JSON_SALES_PRICE)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_IMAGE_ID)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_SHOP_ID)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_DELIVERY_TIME)), 
         curCAT_PDT.getInt(curCAT_PDT.getColumnIndex(DbHelper.JSON_LIKECOUNT)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_VOUCHER_ID)), 
         curCAT_PDT.getString(curCAT_PDT.getColumnIndex(DbHelper.JSON_VOUCHER_OFFER)))); 

       System.out.println("Restaurant category id = " + cartRestaurant.get(0).JSON_CATEGORY_ID + " name = " + cartRestaurant.get(i).JSON_CATEGORY_NAME); 
       i++; 
      } while (curCAT_PDT.moveToNext()); 

      CardAdapter adapter1 = new CardAdapter(cartRestaurant, context); 
      recyclerView.setAdapter(adapter1); 
     } 

     recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 
      @Override 
      public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
       if (dy > 0) { 
        visibleItemCount = mLayoutManager.getChildCount(); 
        totalItemCount = mLayoutManager.getItemCount(); 
        pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition(); 

        if (loading) { 
         if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) { 
          loading = false; 
          Log.v("...", "Last Item Wow !"); 
         } 
        } 
       } 
      } 
     }); 

     edtSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 
      @Override 
      public boolean onQueryTextSubmit(String query) { 
       System.out.println("TabFragment Search" + " query" + query); 
       final List<CartRes> filteredModelList = filter(RestaurantDataSet, query); 
       if (filteredModelList.size() == 0) { 
        Toast.makeText(context, "No Search Data Found", Toast.LENGTH_SHORT).show(); 
       } else { 
        noData.setVisibility(View.GONE); 
       } 
       View view = getActivity().getCurrentFocus(); 
       if (view != null) { 
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
       } 
       return true; 
      } 

      @Override 
      public boolean onQueryTextChange(String newText) { 
       System.out.println("TabFragment Search" + "newText " + newText); 
       final List<CartRes> filteredModelList = filter(RestaurantDataSet, newText); 

       adapter = new CardAdapter(filteredModelList, context); 
       recyclerView.setAdapter(adapter); 
       adapter.notifyDataSetChanged(); 
       recyclerView.scrollToPosition(0); 
       return true; 
      } 
     }); 

     edtSearch.setOnCloseListener(new SearchView.OnCloseListener() { 
      @Override 
      public boolean onClose() { 
       View view = getActivity().getCurrentFocus(); 
       if (view != null) { 
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
       } 
       edtSearch.clearFocus(); 

       recyclerView.setVisibility(View.VISIBLE); 
       noData.setVisibility(View.GONE); 

       return false; 
      } 
     }); 
     noData.setVisibility(View.GONE); 
    } 

Antwort

0

es wurde gelöst durch Ersetzen, Von

endgültige Liste filteredModelList = Filter (RestaurantDataSet, query);

zu

endgültige Liste filteredModelList = Filter (cartRestaurant, query);

edtSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 
      @Override 
      public boolean onQueryTextSubmit(String query) { 
       System.out.println("TabFragment Search" + " query" + query); 
       final List<CartRes> filteredModelList = filter(RestaurantDataSet, query); 
       if (filteredModelList.size() == 0) { 
        Toast.makeText(context, "No Search Data Found", Toast.LENGTH_SHORT).show(); 
       } else { 
        noData.setVisibility(View.GONE); 
       } 
       View view = getActivity().getCurrentFocus(); 
       if (view != null) { 
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
       } 
       return true; 
      } 

      @Override 
      public boolean onQueryTextChange(String newText) { 
       System.out.println("TabFragment Search" + "newText " + newText); 
       final List<CartRes> filteredModelList = filter(RestaurantDataSet, newText); 

       adapter = new CardAdapter(filteredModelList, context); 
       recyclerView.setAdapter(adapter); 
       adapter.notifyDataSetChanged(); 
       recyclerView.scrollToPosition(0); 
       return true; 
      } 
     });