也许这是一个重复的问题,例如:Android:Sherlock action bar drop down,但答案并没有解决我的问题
我想在夏洛克操作栏上实现一个下拉菜单,其中包含一个自定义初始视图,如下所示:
我的代码可以成功创建我想要的列表,但是当我单击该项目时,“onNavigationItemSelected”函数没有收到任何内容
我的代码:
public void someFunction(){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(R.drawable.edit_done);
getSupportActionBar().setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);
final String[] choices = {"Select all"};
CustomSpinnerAdapter spinnerAdapter = new CustomSpinnerAdapter(MainActivity.getInstance(), android.R.layout.simple_spinner_dropdown_item, choices);
getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, this);
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Log.d("OUTPUT", "selected menu position:" + itemPosition);
return true;
}
private class CustomSpinnerAdapter extends ArrayAdapter<String> implements SpinnerAdapter {
private LayoutInflater layoutInflater;
public CustomSpinnerAdapter(Context context, int textViewResourceId, String[] values) {
super(context, textViewResourceId, values);
this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return imageview1;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
convertView = layoutInflater.inflate(R.layout.sherlock_spinner_dropdown_item, parent, false);
((TextView)convertView).setText("Select all");
return convertView;
}
}
如您所见,“onNavigationItemSelected”中的日志仅在调用“somefunction”时出现一次,之后,单击列表项时将看不到任何日志
希望有人能解决我的问题