如何在MaterialBetterSpner库上实现onItemSelected

How can i implement onItemSelected on MaterialBetterSpinner library(如何在MaterialBetterSpner库上实现onItemSelected)

本文介绍了如何在MaterialBetterSpner库上实现onItemSelected的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中实现了以下库微调工具,即从XML

<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
        android:id="@+id/insurer_code"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_insurer_code"
        android:textColor="@color/smart_primary"
        android:textColorHint="@color/input_register_hint"
        app:met_floatingLabel="normal" />

和Java代码

public class testActivity extends Activity implements OnItemSelectedListener

@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

    Toast.makeText(adapterView.getContext(), "Selected: " , Toast.LENGTH_LONG).show();
    // On selecting a spinner item
    String item = adapterView.getItemAtPosition(i).toString();
    // Showing selected spinner item
    Toast.makeText(adapterView.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();

}

但是,当从菜单中选择一个项目时,onItemSelected不会触发。如有关于如何成功实现上述库的任何指导,我们将不胜感激。

推荐答案

只需简单地添加这个,效果就很棒!!`

materialDesignSpinner.setAdapter(arrayAdapter);
        materialDesignSpinner.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                quantity=materialDesignSpinner.getText().toString();
Log.d("value",quantity);

            }
        });

`

这篇关于如何在MaterialBetterSpner库上实现onItemSelected的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在MaterialBetterSpner库上实现onItemSelected

基础教程推荐