0

아래쪽 탐색 서랍 알림에서 작업 중입니다. 알림을 위해 아래쪽 탐색 항목을 클릭하면 잘못된 항목에 아이콘이 표시됩니다. Item5를 클릭하고 거기에 알림을 표시하는 메서드를 호출하면 Item1에 알림 항목이 표시됩니다. 내 코드는 내 화면의 스냅 샷과 함께 아래에 제공됩니다.아래쪽 탐색함에 항목에 잘못된 아이콘이 표시됨

AHBottomNavigation bottomNavigation; 
    Fragment selectedFragment = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     bottomNavigation = (AHBottomNavigation) findViewById(R.id.navigation); 

     AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.home,  R.drawable.home, R.color.colorAccent); 
     AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.menu,  R.drawable.menu, R.color.colorAccent); 
     AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.cart,  R.drawable.cart, R.color.colorAccent); 
     AHBottomNavigationItem item4 = new AHBottomNavigationItem(R.string.orders, R.drawable.orders, R.color.colorAccent); 
     AHBottomNavigationItem item5 = new AHBottomNavigationItem(R.string.settings, R.drawable.setting, R.color.colorAccent); 

     bottomNavigation.addItem(item1); 
     bottomNavigation.addItem(item2); 
     bottomNavigation.addItem(item3); 
     bottomNavigation.addItem(item4); 
     bottomNavigation.addItem(item5); 

     bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); 
     bottomNavigation.setAccentColor(Color.parseColor("#571e19")); 

//  selectedFragment = ItemHomeFragment.newInstance(bottomNavigation); 

     bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() { 
      @Override 
      public boolean onTabSelected(int position, boolean wasSelected) { 

       if (position == 0) { 
        selectedFragment = ItemHomeFragment.newInstance(bottomNavigation); 
       } else if (position == 1) { 
        selectedFragment = ItemMenuFragment.newInstance(bottomNavigation); 
       } else if (position == 2) { 
        selectedFragment = ItemCardFragment.newInstance(bottomNavigation); 
       } else if (position == 3) { 
        selectedFragment = ItemOrdersFragment.newInstance(bottomNavigation); 
       } else if (position == 4) { 
        selectedFragment = ItemSettingsFragment.newInstance(bottomNavigation); 
       } 

       android.app.FragmentManager fragmentManager = getFragmentManager(); 
       android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
       fragmentTransaction.replace(R.id.frame_layout,selectedFragment); 
       fragmentTransaction.commit(); 


       return true; 

      } 

     }); 

    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     android.app.FragmentManager fragmentManager = getFragmentManager(); 
     android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
     fragmentTransaction.replace(R.id.frame_layout, ItemHomeFragment.newInstance(bottomNavigation)); 
     fragmentTransaction.commit(); 

    } 

내 조각 클래스 :

MainActivity 클래스 : 내 조각 클래스는 아래와 같습니다 Item5에서

public class ItemSettingsFragment extends Fragment { 

    public static AHBottomNavigation bottomNavigation1; 

    public static ItemSettingsFragment newInstance(AHBottomNavigation bottomNavigation) { 
     ItemSettingsFragment fragment = new ItemSettingsFragment(); 
     // Initializing Navigation Drawer 
     bottomNavigation1 = bottomNavigation; 
     return fragment; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 


     View view = inflater.inflate(R.layout.fragment_settings, container, false); 

     setNotification(); 
     return view; 

    } 


    // Calling this method in my 5 Item of Notification Drawer, but '1' is showing in first item of Bottom Noficiation drawer 
    public static void setNotification(){ 
     bottomNavigation1.setNotification("1", 1); 
    } 

} 

클릭하지만 알림 아이콘 내 알림 서랍 항목의 항목 2에 게재됩니다.

enter image description here

답변

0

전체에서 코드를 확인한 후 을 비교하십시오. AHBottomNavigation에 대한 github 레포와 비교하십시오. 나는 그 작은 실수를 발견했다. 탭 카운터 0으로 시작하기 때문에 지금

public static void setNotification(){ 
    bottomNavigation1.setNotification("1", 1); 
} 

이 줄을 확인

는 첫 번째 매개 변수는 알림 카운터이며, 두 번째 매개 변수는, 당신은 통과, '1'탭에서 설정 알림 배지를 의미하는 '1'을하는 당신의 탭 번호와 그것이 두 번째 탭에 설정되는 이유입니다.

대답은 간단합니다. 응답이

public static void setNotification(){ 
    bottomNavigation1.setNotification("1", 4); 
} 
+0

덕분 그냥 변화에게 그것을. 나는 어리석은 실수를 저 지르고 있었다. 고마워 많이 작동합니다. –

+1

당신이 가장 환영합니다 :) 투표 해 주셔서 감사합니다 – Najam

+0

나는 당신이 내 솔루션을 확인하는 것이 좋습니다, 당신이 그것을 놓친 것,이 전에 게시되었습니다. Najam, 값을 변경하는 것이 최선의 해결책은 아니므로 인수를 추가하여 메서드를 수정할 때 메서드를 호출 할 때 변수를 사용할 수있는 방법을 제안했습니다. 이것은 더 많은 유연성을 제공합니다.U Khan, 알림을 늘리거나 제거해야하는 경우 제안 된 디자인과 같은 디자인이 필요합니다. 희망이 도움이됩니다. –

0

당신이 할 경우 :

public static void setNotification(){ 
    bottomNavigation1.setNotification("1", 1); 
} 

"1"알림

일이다

그래서 당신이받은 위치에있는 항목의 알림을 설정하는 항목받은 위치를 1 : '메뉴'

당신이 할 수있는 무엇 :

setNotification("Any message or number", yourItemPostion) 

예 : 당신이 메서드를 호출 할 때,

public static void setNotification(String notification, int itemPostion){ 
bottomNavigation1.setNotification(motification, itemPostion); 

} 그런 다음

:

이 방법이 방법을 수정하여 설정을 "2" 설정 :

setNotification("2", 4)