Пример #1
0
 // 如果视图定义了OnClickListener监听器,调用此方法来执行
 @Override
 public boolean performClick() {
   Context context = getContext();
   final LayoutInflater inflater = LayoutInflater.from(getContext());
   final View view = inflater.inflate(R.layout.spinner_list, null);
   final ListView listview = (ListView) view.findViewById(R.id.formcustomspinner_list);
   ListviewAdapter adapters = new ListviewAdapter(context, getList());
   listview.setAdapter(adapters);
   listview.setOnItemClickListener(this);
   dialog = new SelectDialog(context, R.style.dialog); // 创建Dialog并设置样式主题
   LayoutParams params = new LayoutParams(650, LayoutParams.FILL_PARENT);
   dialog.setCanceledOnTouchOutside(true); // 设置点击Dialog外部任意区域关闭Dialog
   dialog.show();
   dialog.addContentView(view, params);
   return true;
 }
Пример #2
0
  @Override
  public void onItemClick(AdapterView<?> view, View itemView, int position, long id) {
    setSelection(position);
    setText(list.get(position));
    if (dialog != null) {
      dialog.dismiss();
      dialog = null;
    }

    mOnItemChosedListener.onItemChosed(position);
  }