Bigkoo / Android-PickerView

This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
Apache License 2.0
13.44k stars 3.45k forks source link

Problem with datas #323

Closed helsephas closed 7 years ago

helsephas commented 7 years ago

Hello, first, i m sorry i don't speak chinese. I want to know if i can adapt the list at runtime for exemple:

我试图用中文来传播 你好,首先,我很抱歉,我不会说中文。 我想知道我是否可以在运行时调整列表,例如: 轮A包含A1,A2,A3 轮B包含B1A1,B2A1, B1A2,B2A2, B1A3,B2A3, 所以如果A1如果选择B1A1和B2A1显示,A2 B1A2和B2A2等...

xiaosong520 commented 7 years ago

@helsephas You mean that you need the options change as long as item changes? or next time you open it, change the default selection? “So if A1 if selected B1A1 and B2A1 is showing, A2 B1A2 and B2A2, etc , ...” Can you describe it more clearly? I don't quite understand this. Waiting for your reply~

helsephas commented 7 years ago

Yes the options2 changes as long as item changes in option 1. Its seems to be like this : https://github.com/Bigkoo/Android-PickerView/blob/master/preview/JsonData.gif. Options2 list depends on options1 seletected item

xiaosong520 commented 7 years ago

@helsephas The steps to add datas are as follows:

private ArrayList<String> options1Items = new ArrayList<>();
private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();

        //options1 data
        options1Items.add(A1);
        options1Items.add(A2);

        //options2

        ArrayList<String> options2Items_01 = new ArrayList<>();
        options2Items_01.add(B21);
        options2Items_01.add(B22);
        ArrayList<String> options2Items_02 = new ArrayList<>();
        options2Items_02.add(B11);
        options2Items_02.add(B12);

        options2Items.add(options2Items_01);
        options2Items.add(options2Items_02);

        pvOptions.setPicker(options1Items, options2Items);
xiaosong520 commented 7 years ago

@helsephas It can be either data of type String or entity data. If you add entity data,your entity class need implements ”IPickerViewData“ interface, and then, In the "getPickerViewText" method, returns the String data what you needs to be displayed.

xiaosong520 commented 7 years ago

@helsephas set linkage picker data after you add data list, like this:

pvOptions.setPicker(options1Items, options2Items);
//or
pvOptions.setPicker(options1Items, options2Items,options3Items);
helsephas commented 7 years ago

Thanks for your replies. I have make some tries but i m still blocked with this code and i seem to use your picker exactly like you

I m working in kotlin

I used this like this : var pickerViewDates = MyOptionsPickerView(this) pickerViewDates.setTitle(this.resources.getString(R.string.shopping_cart_pick_date_title)) var now : Date = Date() var days : ArrayList = ArrayList() var hours : ArrayList<ArrayList> = ArrayList() var minutes : ArrayList<ArrayList> = ArrayList() //init arrays pickerViewDates.setPicker(days,hours,minutes,true) pickerViewDates.setCyclic(true,true,true) pickerViewDates.show()

-> I get an error because type is mismatching (required: ArrayList<String!>! found ArrayList<ArrayList>

xiaosong520 commented 7 years ago

@helsephas Do you need to use timePicker? as follows:

        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(2013, 0, 1);

        Calendar endDate = Calendar.getInstance();
        endDate.set(2017, 11, 1);

        pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//callback
            }
        })
                .setType(new boolean[]{false, false, false, true, true, true}) // day - hour - minute
                .setLabel("", "", "", "", "", "")
                .setDividerColor(Color.DKGRAY)
                .setContentSize(21)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .build();
    }
xiaosong520 commented 7 years ago

@helsephas Calendar's month value is 0-based. e.g., 0 for January.

helsephas commented 7 years ago

I can't use time picker because i got a set of ranges dates for example i will get 17 july 8->16 hours 0-> 59 minutes 19 july 8->16 hours 0-> 59 minutes 21 july 9-> 20hours 0-> 59 minutes etc etc thats why i use String and not date. My problem is that i can't add arrayList like you did in your example for option 2 because i said that my optionPickerView will be type String and not ArrayList of String thats what i don't understand and we got the same code apparently

xiaosong520 commented 7 years ago

@helsephas 1. You can used the linkage datatype. For details, please refer to the fourth reply , dataType :

var days : ArrayList = ArrayList() 
var hours : ArrayList<ArrayList> = ArrayList()
var minutes : ArrayList<ArrayList<ArrayList>> = ArrayList()
  1. Or self modify the source code to implement this function( let option1 and option2 linked, option3 is no-linkage), dataType :
    var days : ArrayList = ArrayList()
    var hours : ArrayList<ArrayList> = ArrayList()  // depend on day
    var minutes : ArrayList = ArrayList()     // 0-59
helsephas commented 7 years ago

Oki i m sorry for all this. Because my problem was simply that : I used MyOptionsPickerView and not OptionsPickerView so i waste our both time. I m sorry for this. Thanks for all this replies and for your time. Have a nice day.