键盘事件  keycode表示一个对应的值(按下A键)  getAction 表示一个对应的动作(按下)

@Override
   public boolean onKey(View v, int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_BACK){
     Toast.makeText(getApplicationContext(), "返回", 1000).show();
    }
    
//    switch (event.getAction()) {
//    case KeyEvent.ACTION_DOWN:
//     Toast.makeText(getApplicationContext(), "你按下了我", Toast.LENGTH_SHORT).show();
//     break;
//    case KeyEvent.ACTION_UP:
//     Toast.makeText(getApplicationContext(), "滚开,我要起来", Toast.LENGTH_SHORT).show();
//     break;
//
//    default:
//     break;
//    }
    return true;
   }
  } );
 }

 

//

List view

SimpleAdapter适配器

//把集合数据放在集合里面
  List< Map<String,Object >> data = new ArrayList<Map<String,Object>>();
  for (int i = 0; i < names.length; i++) {
   Map<String, Object> map= new HashMap<String,Object >();
   map.put("imgs", imgs[i]);
   map.put("name", names[i]);
   data.add(map);
  }
  //找到适配器,加载数据,加载布局,我们什么数据类型
  SimpleAdapter adapter=new SimpleAdapter
    (this, data, R.layout.list_item, new String[]{"imgs","name"}, new int[]{R.id.iv_icon,R.id.tv_name});
  //加载适配
  lv.setAdapter(adapter);

AraayAdapter适配器

 sp_city = (Spinner) findViewById(R.id.sp_city);
  sp_city.setPrompt("你喜欢的老师是哪位?");
  List<String> list=new ArrayList<String>();
  list.add("苍老师");
  list.add("左老师");
  list.add("王老师");
  list.add("程老师");
  //获取加载容器
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
  //添加
  sp_city.setAdapter(adapter);