我試試這兩個庫來創建我的android應用程序NewQuickAction和NewQuickAction3D中的按鈕菜單。安卓菜單庫:NewQuickAction3D沒有工作
使用它們的代碼是相同的! 但是,如果使用NewQuickAction它正常工作,而不是如果我改變外部庫在我的項目,我用NewQuickAction3D,它不工作,返回此錯誤:
FATAL EXCEPTION: main java.lang.NullPointerException at net.londatiga.android.QuickAction.addActionItem(QuickAction.java:213)
的代碼是:
ActionItem myLocationItem = new ActionItem(ID_MY_LOCATION, "Mia posizione", getResources().getDrawable(R.drawable.location));
ActionItem nearestItem = new ActionItem(ID_NEAREST_STATION, "Stazione piu vicina", getResources().getDrawable(R.drawable.location));
ActionItem activeGpsItem = new ActionItem(ID_ACTIVE_GPS, "Attiva GPS", getResources().getDrawable(R.drawable.gps));
// constructor for NewQuickAction
final QuickAction mQuickAction = new QuickAction(this);
// constructor for NewQuickAction3D
//final QuickAction mQuickAction = new QuickAction(this, QuickAction.VERTICAL);
mQuickAction.addActionItem(myLocationItem);
mQuickAction.addActionItem(nearestItem);
mQuickAction.addActionItem(activeGpsItem);
//setup the action item click listener
mQuickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
@Override
public void onItemClick(QuickAction quickAction, int pos, int actionId) {
if (actionId == ID_MY_LOCATION) {
Toast.makeText(getApplicationContext(), "I have no info this time", Toast.LENGTH_SHORT).show();
} else if (actionId == ID_NEAREST_STATION) {
Toast.makeText(getApplicationContext(), "I have no info this time", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
}
});
ImageButton buttonMenu = (ImageButton) findViewById(R.id.button_menu);
buttonMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mQuickAction.show(v);
}
});
看來,用於創建一個新的ActionItem圖標和文本不符合NewQuickAction3D
可見如果我運行庫作爲一個正常的項目(庫也是一個示範項目),他們的工作正常。
有什麼想法?
發佈您的代碼。 – rajpara
@rajpara我添加代碼 – lory105
沒有消息對我的問題? – lory105