我有一个带有操作栏的应用程序,该操作栏具有下拉导航功能(如微调器)。是否可以以编程方式从列表中删除项目?
编辑:相关代码:
// Set up the dropdown list navigation in the action bar.
actionBar.setListNavigationCallbacks(
// Specify a SpinnerAdapter to populate the dropdown list.
new ArrayAdapter<String>(getActionBarThemedContextCompat(),
android.R.layout.simple_list_item_1,
android.R.id.text1, list), this);
答案 0 :(得分:1)
以下是移除操作栏中(Spinner )
import java.util.ArrayList;
import java.util.List;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
public class MainActivity extends Activity implements
ActionBar.OnNavigationListener {
ActionBar actionBar;
List spinnerList;
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
spinnerList = new ArrayList();
spinnerList.add("Item1");
spinnerList.add("Item2");
spinnerList.add("Item3");
spinnerList.add("Item4");
adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, spinnerList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
actionBar.setListNavigationCallbacks(adapter, this);
removeItemInActionBar(2);
}
public void removeItemInActionBar(int position) {
spinnerList.remove(position);
adapter.notifyDataSetChanged();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
// TODO Auto-generated method stub
return false;
}
}