其他分享
首页 > 其他分享> > PickerView是什么

PickerView是什么

作者:互联网

PickerView是什么


仿ios的PickerView控件,带有3D圆弧效果,并封装了时间选择和选项选择这两种选择器。

效果:
在这里插入图片描述

导包

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

用法:
XM中的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   <com.contrarywind.view.WheelView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:id="@+id/wv"
       ></com.contrarywind.view.WheelView>
</LinearLayout>

Activity代码:

package com.example.day011;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

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 wv;
    private ArrayWheelAdapter<String> myAdapter;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        wv.setOnItemSelectedListener(new OnItemSelectedListener() {
//            @Override
//            public void onItemSelected(int index) {
//                Log.i(TAG, "onItemSelected: "+index);
//            }
//        });

        wv = findViewById(R.id.wv);
        List<String> list=new ArrayList<>();
        list.add("好家伙");
        list.add("厉害了");
        list.add("哈哈哈");
         myAdapter = new ArrayWheelAdapter<>(list);
         wv.setAdapter(myAdapter);

    }
}

标签:PickerView,什么,list,private,wv,import,com
来源: https://blog.csdn.net/weixin_46177591/article/details/114283249