功能展示——自定义控件Spinner样式实现下拉列表

一、效果图

功能展示——自定义控件Spinner样式实现下拉列表_第1张图片

二、导入步骤

按照文件依次导入–>文件地址

三、使用步骤

1、布局引用

<com.daqsoft.yspinner.views.NiceSpinner
        android:id="@+id/nice_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

2、主页面

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import com.daqsoft.yspinner.views.NiceSpinner;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        NiceSpinner niceSpinner = (NiceSpinner) findViewById(R.id.nice_spinner);
        List dataset = new LinkedList<>(Arrays.asList("One", "Two", "Three", "Four", "Five","One", "Two", "Three", "Four", "Five","One", "Two", "Three", "Four", "Five"));
        niceSpinner.attachDataSource(dataset);
        niceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView adapterView, View view, int i, long l) {
                Toast.makeText(MainActivity.this,"你选中了"+i,Toast.LENGTH_LONG).show();
            }
            @Override
            public void onNothingSelected(AdapterView adapterView) {

            }
        });
    }
}

你可能感兴趣的:(【功能展示】,spinner,android)