Skip to content

Commit

Permalink
设置初始数据
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyong committed Aug 19, 2020
1 parent 9e54c28 commit 0cc5fc4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
14 changes: 11 additions & 3 deletions app/src/main/java/com/wp/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import java.util.List;

public class MainActivity extends Activity {
private Date mInitBirthday = new Date();
private Date mInitDate = new Date();
private Date mInitFutureDateTime = new Date();
private Date mInitFutureDate = new Date();

private Student mInitData = null;
private List<Integer> mMultiInitIndex = null;
private List<Integer> mCascadeInitIndex = null;
Expand All @@ -35,10 +40,11 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View view) {

DataPicker.pickBirthday(MainActivity.this, new Date(System.currentTimeMillis()),
DataPicker.pickBirthday(MainActivity.this, mInitBirthday,
new OnDatePickListener() {
@Override
public void onDatePicked(long time, int year, int month, int day, int hour, int minute, int second) {
mInitBirthday.setTime(time);
Toast.makeText(MainActivity.this, year + "-" + (month + 1) + "-" + day, Toast.LENGTH_SHORT).show();
}
});
Expand All @@ -49,10 +55,11 @@ public void onDatePicked(long time, int year, int month, int day, int hour, int
findViewById(R.id.picker_date).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DataPicker.pickDate(MainActivity.this, new Date(System.currentTimeMillis()),
DataPicker.pickDate(MainActivity.this, mInitDate,
DateWheelPicker.TYPE_ALL, 100, 100, new OnDatePickListener() {
@Override
public void onDatePicked(long time, int year, int month, int day, int hour, int minute, int second) {
mInitDate.setTime(time);
Toast.makeText(MainActivity.this, year + "-" + (month + 1) + "-" + day + " " + hour + ":" + minute, Toast.LENGTH_SHORT).show();
}
});
Expand All @@ -64,10 +71,11 @@ public void onDatePicked(long time, int year, int month, int day, int hour, int
findViewById(R.id.picker_future_date).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DataPicker.pickDate(MainActivity.this, new Date(System.currentTimeMillis()),
DataPicker.pickDate(MainActivity.this, mInitFutureDateTime,
DateWheelPicker.TYPE_ALL, 0, 100, new OnDatePickListener() {
@Override
public void onDatePicked(long time, int year, int month, int day, int hour, int minute, int second) {
mInitFutureDateTime.setTime(time);
Toast.makeText(MainActivity.this, year + "-" + (month + 1) + "-" + day + " " + hour + ":" + minute, Toast.LENGTH_SHORT).show();
}
});
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/com/wheelpicker/AdministrativeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static List<List<?>> getDefaultPickString(AdministrativeMap map) {
return pickDataList;
}

public static List<List<?>> getPickData(AdministrativeMap map, List<?> indexArr) {
public static List<List<?>> getPickData(AdministrativeMap map, List<Integer> indexArr) {
if (map == null) {
return null;
}
Expand All @@ -72,8 +72,8 @@ public static List<List<?>> getPickData(AdministrativeMap map, List<?> indexArr)
pickDataList.add(map.provinces.get(0).city);
pickDataList.add(map.provinces.get(0).city.get(0).areas);
} else {
int cityIndex = (Integer) indexArr.get(0);
int areaIndex = (Integer) indexArr.get(1);
int cityIndex = indexArr.get(0);
int areaIndex = indexArr.get(1);
pickDataList.add(map.provinces);
pickDataList.add(map.provinces.get(cityIndex).city);
pickDataList.add(map.provinces.get(cityIndex).city.get(areaIndex).areas);
Expand Down
5 changes: 4 additions & 1 deletion library/src/main/java/com/wheelpicker/DataPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.wheelpicker.core.WheelPickerUtil;
import com.wheelpicker.widget.IPickerView;
import com.wheelpicker.widget.TextWheelPickerAdapter;

Expand Down Expand Up @@ -118,7 +119,7 @@ public static void pickFutureDate(Context context, @Nullable Date initDate, int
.build();
final FutureTimePicker picker = (FutureTimePicker) buildDateWheelPicker(context, option, PickMode.MODE_FUTURE_DATE);
picker.setPickedTime(calendar.getTimeInMillis());
picker.notifyDataSetChanged();
//picker.notifyDataSetChanged();

BottomSheet bottomSheet = buildBottomSheet(context, picker);
bottomSheet.show();
Expand Down Expand Up @@ -151,6 +152,8 @@ public static <T> void pickData(Context context, @Nullable T initData, @NonNull

TextWheelPickerAdapter adapter = new TextWheelPickerAdapter(srcData);
picker.setAdapter(adapter);
int index = WheelPickerUtil.indexOf(initData, srcData);
picker.setCurrentItem(index < 0 ? 0 : index);

BottomSheet bottomSheet = buildBottomSheet(context, picker);
bottomSheet.show();
Expand Down

0 comments on commit 0cc5fc4

Please sign in to comment.