Spinner performclick() not working

前端 未结 1 1451
走了就别回头了
走了就别回头了 2021-01-28 12:22

I want the spinner to open up by itself when I run the activity, so I\'m using the performClick() method but it\'s showing this error:

Caused by: andr

1条回答
  •  孤城傲影
    2021-01-28 13:00

    For spinner you have don't need to implement "AdapterView.OnItemSelectedListener" Create like this .

    spinner1 = (Spinner) findViewById(R.id. spinner1);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
                suggestions, android.R.layout.simple_spinner_item);
        adapter1.setDropDownViewResource(
                android.R.layout.simple_spinner_dropdown_item);
        spinner1.setAdapter(adapter);
        spinner1.performClick();
    

    // Get selecte index or Suggestions

    spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView parent, View view,
                int pos, long id) {
            String selectedSugg = suggestions[pos];
            Log.d("Suggestions ", selectedSugg);
        }
    
        @Override
        public void onNothingSelected(AdapterView arg0) {
    
        }
    });
    

    0 讨论(0)
提交回复
热议问题