PickView

标题@TOC

所需程序包

相关代码

实现效果

程序包

implementation 'com.contrarywind:Android-PickerView:4.1.9'

相关代码

package com.example.day_3_2_sheel;

import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private WheelView wheelView;
    ArrayWheelAdapter<String> myadapter;
    List<String> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        wheelView.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                Toast.makeText(MainActivity.this, ""+list.get(index), Toast.LENGTH_SHORT).show();
            }
        });
         list=new ArrayList<>();
        list.add("丰裕之角");
        list.add("第戎学院");
        list.add("小镇庙会");
         myadapter=new ArrayWheelAdapter(list);
        wheelView.setAdapter(myadapter);
    }

    private void initView() {
        wheelView = (WheelView) findViewById(R.id.wheel_view);
    }
}

功能图

轮框效果

级联

 private void initOptionPicker() {
        final List<String> options1Items = new ArrayList<>();
        options1Items.add("射雕英雄传");
        options1Items.add("神雕侠侣");
        options1Items.add("鹿鼎记");

        List<String> options2Items_01 = new ArrayList<>();
        options2Items_01.add("郭靖");
        options2Items_01.add("黄蓉");
        options2Items_01.add("杨铁心");
        options2Items_01.add("欧阳克");
        List<String> options2Items_02 = new ArrayList<>();
        options2Items_02.add("小龙女");
        options2Items_02.add("杨过");
        options2Items_02.add("大雕");
        List<String> options2Items_03 = new ArrayList<>();
        options2Items_03.add("小柜子");
        options2Items_03.add("康熙");
        options2Items_03.add("康亲王");
        options2Items_03.add("鳌拜");

        final List<List<String>> options2Items = new ArrayList<>();
        options2Items.add(options2Items_01);
        options2Items.add(options2Items_02);
        options2Items.add(options2Items_03);


        OptionsPickerView optionsPickerView = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String tx = options1Items.get(options1)
                        + options2Items.get(options1).get(options2);
                Toast.makeText(getBaseContext(), tx, Toast.LENGTH_SHORT).show();
            }
        })
                .setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
                    @Override
                    public void onOptionsSelectChanged(int options1, int options2, int options3) {
                        String str = "options1: " + options1 + "\noptions2: " + options2 + "\noptions3: " + options3;
                        Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
                    }
                })
                .build();

        optionsPickerView.setPicker(options1Items, options2Items);
        optionsPickerView.show();
    }```
![级联](https://img-blog.csdnimg.cn/20210302141253174.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xpZ2h0MDI=,size_16,color_FFFFFF,t_70)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值