0
아래 이미지와 같이 개수 및 남은 메뉴 항목이 기본 유형 인 항목을 표시하는 하나의 맞춤 메뉴 항목을 표시하려는 애플리케이션을 개발 중입니다.Android : 맞춤 옵션 메뉴
는 menu.xml의 내 코드는 다음과입니다 :
는<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/menu_1"
android:icon="@drawable/icon_1"
android:orderInCategory="101"
android:title="@string/option_1"
myapp:showAsAction="always"/>
<item
android:id="@+id/menu_2"
android:icon="@drawable/icon_2"
android:orderInCategory="102"
android:title="@string/option_2"
myapp:showAsAction="always"/>
<item
android:id="@+id/menu_3"
android:icon="@drawable/icon_3"
android:orderInCategory="103"
android:title="@string/option_3"
myapp:showAsAction="always"/>
<item
android:id="@+id/menu_4"
android:icon="@drawable/icon_4"
android:orderInCategory="104"
android:title="@string/option_4"
myapp:showAsAction="always"/>
<item
android:id="@+id/menu_5"
android:orderInCategory="105"
android:title="@string/option_5"
myapp:showAsAction="never"
android:actionLayout="@layout/actionbar_badge_layout" />
</menu>
actionbar_badge_layout.xml의 내 코드입니다 : 내가 무슨 짓을 내 조각에서
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:id="@+id/actionbar_badge_layout" >
<TextView
android:id="@+id/actionbar_notifcation_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:padding="10dp"
android:text="@string/option_1"
android:textColor="@android:color/black"
android:layout_toLeftOf="@+id/actionbar_notifcation_count_textview"/>
<TextView
android:id="@+id/actionbar_notifcation_count_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dp"
android:text="99"
android:textColor="@android:color/white"
android:background="@drawable/badge_circle" />
</RelativeLayout>
은
:@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_myfragment, container,false);
setHasOptionsMenu(true);
((SlidingBaseActivity) getActivity()).setActionBarTitle("My Fragment");
((SlidingBaseActivity) getActivity()).keepMenuClosed(false);
((SlidingBaseActivity) getActivity()).makeActionOverflowMenuShown();
initView(view);
dialog = Helper.showPleaseWaitDialog(getActivity());
getdata();
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.findItem(R.id.option_1).setVisible(true);
menu.findItem(R.id.option_1).setOnMenuItemClickListener(this);
menu.findItem(R.id.option_2).setVisible(true);
menu.findItem(R.id.option_2).setOnMenuItemClickListener(this);
menu.findItem(R.id.option_3).setVisible(true);
menu.findItem(R.id.option_3).setOnMenuItemClickListener(this);
menu.findItem(R.id.option_4).setVisible(true);
menu.findItem(R.id.option_4).setOnMenuItemClickListener(this);
menu.findItem(R.id.option_5).setVisible(true);
menu.findItem(R.id.option_5).setOnMenuItemClickListener(this);
RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.option_5).getActionView();
TextView textViewMenuText = (TextView) badgeLayout.findViewById(R.id.actionbar_notifcation_textview);
textViewMenuText.setText("Notification ");
TextView textViewCount = (TextView) badgeLayout.findViewById(R.id.actionbar_notifcation_count_textview);
textViewCount.setText("99");
super.onCreateOptionsMenu(menu, inflater);
}
하지만 각 조각을 탐색 할 때 널 포인터 예외이 발생합니다. 나는 최대 투표 결과를 this link.
에 따르고 있습니다. 무엇이 잘못되었거나 잘못 되었습니까? 나를 안내 해줘.