我在menu_main中使用actionProviderClass去設定actionbar的內容,
(android:actionProviderClass="com.kermitlin.imha.FilterActionProvider")
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="@+id/gp2">
<item
android:id="@+id/tb_InstaChat"
android:icon="@drawable/ic_autorenew_white_24dp"
android:actionProviderClass="com.kermitlin.imha.FilterActionProvider"
android:orderInCategory="2"
android:showAsAction="ifRoom"
android:title="tt2" />
</group>
</menu>
以下是FilterActionProvider
public class FilterActionProvider extends ActionProvider {
public FilterActionProvider(Context context) {
super(context);
}
@Override
public View onCreateActionView() {
return null;
}
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
subMenu.clear();
DBOperator db;
db = new DBOperator(this.getApplication().getPackageName(), this);
db.open(); //我在這邊就會錯誤,無法使用getApplication()
subMenu.add("Reminders").setIcon(R.drawable.ic_launcher)
.setOnMenuItemClickListener(new
MenuItem.OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item) {
return true;
}
});
}
@Override
public boolean hasSubMenu() {
return true;
}
}
我想要請問應該如何在MyactionProvider中使用sqlite,
或是說應該要如何解決getApplication()的問題,
抱歉我是初學者如果問題太愚蠢請多包涵,謝謝<(_ _)>