Android自定义组合控件:SherlockSpinner

  • 选中ListPopupWindow的某一项后,将此项内容更新到EditText中,并隐藏ListPopupWindow
  • etLanguages = (EditText) findViewById(R.id.et_languages);etLanguages.setKeyListener(null); // 设置EditText不可编辑,等同于在xml中设置editable="false"lpwLanguages = new ListPopupWindow(this);mAdapterLanguages = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mLanguages);lpwLanguages.setAdapter(mAdapterLanguages);lpwLanguages.setAnchorView(etLanguages); //设置ListPopupWindow的锚点,即关联PopupWindow的显示位置lpwLanguages.setModal(true); // 是否为模态,当设置为true时,会处理返回按键的事件lpwLanguages.setOnItemClickListener(new AdapterView.OnItemClickListener() {    @Override    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {        showMessage("Select " + mLanguages[position]);        etLanguages.setText(mLanguages[position]);        lpwLanguages.dismiss();    }});// 如果使用onClick事件,会出现第一次点击只获取焦点,第二次点击才出现下拉etLanguages.setOnTouchListener(new View.OnTouchListener() {    @Override    public boolean onTouch(View v, MotionEvent event) {        if (event.getAction() == MotionEvent.ACTION_DOWN) {            // Do what you want            getDataFromNet();        }        return false;    }});public void getDataFromNet() {    // 延时2秒后,修改源数据,用来模拟网络请求    new Thread(new Runnable() {        @Override        public void run()