显示打开的旋转器

发布于 2025-01-07 02:49:54 字数 843 浏览 1 评论 0原文

我有异步任务来为我提供一些城市的列表,在获得列表后,我想直接向我显示一个打开的微调器,而不需要任何对话框。我的代码使用正确的列表打开微调器,但 clickListener 似乎不起作用。

我的代码:

ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerCities);
    listAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner = new Spinner(this);
    spinner.setAdapter(listAdapter);
    spinner.performClick();
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> aView, View selectedItemView,
                int position, long longID) {
                    System.out.println("ON ITEM CLICK LISTENER HERE");
        }
        public void onNothingSelected(AdapterView<?> aView) {
        }
    });

我在这里缺少什么?

I have Async task to provide me list of some cities and after I have the list, I want to show me an OPEN spinner directly without any dialogs. My code opens spinner with propper list, but clickListener doesn't seems to work.

my code:

ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerCities);
    listAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner = new Spinner(this);
    spinner.setAdapter(listAdapter);
    spinner.performClick();
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> aView, View selectedItemView,
                int position, long longID) {
                    System.out.println("ON ITEM CLICK LISTENER HERE");
        }
        public void onNothingSelected(AdapterView<?> aView) {
        }
    });

What I am missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尾戒 2025-01-14 02:49:54

所以几个小时后,我想通了。我需要使用 Dialog,但结果与我想要的相同。这是来源,以防有人发现有用。

private void MyMethod(){
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, 
            (String[])MyClass.getListOfCities().toArray());
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setIcon(icon);
    ad.setTitle("Title");
    ad.setSingleChoiceItems( listAdapter, -1, new OnClickListener() {
        public void onClick(DialogInterface dialog, int position) {
            // DO something when I click on item
            dialog.dismiss();
        }
    });
    ad.show();
}

So after several hours, I figured it out. I need to use Dialog, but result is the same I have wanted. Here is source in case, someone is find useful.

private void MyMethod(){
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, 
            (String[])MyClass.getListOfCities().toArray());
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setIcon(icon);
    ad.setTitle("Title");
    ad.setSingleChoiceItems( listAdapter, -1, new OnClickListener() {
        public void onClick(DialogInterface dialog, int position) {
            // DO something when I click on item
            dialog.dismiss();
        }
    });
    ad.show();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文