效果图:
关键代码:
String kindName;
//此处为数据库链接:
kdao = new KindDao(this.getBaseContext());
ArrayList<String> kindlist = (ArrayList<String>) kdao.find();
//将可选内容与ArrayAdapter连接
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,kindlist);
//设置下拉列表风格
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//将adapter添加到keep_kind中
keep_kind.setAdapter(adapter);
//添加事件监听
keep_kind.setOnItemSelectedListener(spinnerListener);
private OnItemSelectedListener spinnerListener = new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id)
{
//此处为选择后的动作事件
kindName = kindlist.get(position);
parent.setVisibility(View.VISIBLE);
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
// TODO Auto-generated method stub
}
};