Spinner on Button click not responding to Click ev

2019-09-21 00:42发布

I have a spinner which drops down when a button is clicked. But when I am trying to set onItemSelectedListener, it is not taking the click events.

spnrLocation.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View arg1,
                    int arg2, long arg3) {
                System.out.println("location clicked" + arg2);
                edtLocation.setText(parent.getItemAtPosition(arg2).toString());
                System.out.println("wfefe"
                        + parent.getItemAtPosition(arg2).toString());
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });

2条回答
祖国的老花朵
2楼-- · 2019-09-21 01:14

Any View supports the android:clickable attribute (which lets you make any View behave like a Button). There is also android:focusable.

查看更多
孤傲高冷的网名
3楼-- · 2019-09-21 01:31
// try this
spnrLocation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                System.out.println("location clicked" + i);
                edtLocation.setText(spnrLocation.getSelectedItem().toString());
                System.out.println("wfefe"
                        + spnrLocation.getSelectedItem().toString());
            }
        });
查看更多
登录 后发表回答