我有以下
我正在使用操作栏和微调器,但我想要添加一个像 City subtitles => All , City 1 , City 2 的字幕
喜欢这张图片
我有以下菜单 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/filter1"
android:showAsAction="ifRoom"
android:orderInCategory="1"
android:actionViewClass="android.widget.Spinner"
/>
<item
android:id="@+id/filter2"
android:showAsAction="ifRoom"
android:orderInCategory="1"
android:actionViewClass="android.widget.Spinner" />
</menu>
这在活动中
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search_menu, menu);
mSpinnerItem1 = menu.findItem(R.id.filter1);
mSpinnerItem2 = menu.findItem(R.id.filter2);
setupSearchView();
View view1 = mSpinnerItem1.getActionView();
if (view1 instanceof Spinner) {
Spinner spinner = (Spinner) view1;
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.filters, android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mDbHelper.open();
showResults();
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
View view2 = mSpinnerItem2.getActionView();
if (view2 instanceof Spinner) {
Spinner spinner = (Spinner) view2;
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.cities, android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mDbHelper.open();
showResults();
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
return true;
}