setOnItemClickListener doesn't work with Android Spinner

前端 未结 8 851
说谎
说谎 2020-12-17 17:37

setOnItemClickListener doesn\'t work with android Spinner. Here is my code:

supplier.setOnItemClickListener(new OnItemClickListener() {

                @Ove         


        
相关标签:
8条回答
  • 2020-12-17 18:28

    I think supplier in your code means spinner, do Replace this line

     String msupplier=supplier.getSelectedItem().toString();
    

    with the below line:

     String msupplier= supplier.getItemAtPosition(position).toString(); 
    
    0 讨论(0)
  • 2020-12-17 18:33

    i have faced this issues. setOnItemClickListener will not works with spinner. My solution is as following:

    mSpinnerYears.setAdapter(adapter);
        mSpinnerYears.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Logger.d(new StringBuilder(2).append("TAG:").append(TAG).toString(),
                        new StringBuilder(3).append("click pos = ").append(position).append(
                                mSpinnerYears.getItemAtPosition(position).toString()).toString());
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题