我是Android编程的初学者。我正在尝试在片段中添加日历( https://github.com/square/android-times-square )
public class CalendarFragment extends Fragment {
private static final String TAG = "CalendarFragment";
View viewer;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewer = (View) inflater.inflate(R.layout.cal, container,
false);
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
final CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar);
calendar.init(new Date(), new Date(), nextYear.getTime());
Button b = (Button) findViewById(R.id.done_button);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "Selected time in millis: " + calendar.getSelectedDate().getTime());
String toast = "Selected: " + calendar.getSelectedDate().getTime();
Toast.makeText(CalendarFragment.this, toast, LENGTH_SHORT).show();
}
});
return viewer;
}
cal.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.squareup.timessquare.CalendarPickerView
android:id="@+id/calendar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:scrollbarStyle="outsideOverlay"
android:clipToPadding="false"
android:background="#FFFFFF"
/>
<Button
android:id="@+id/done_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Done"
/>
</LinearLayout>
我认为问题出在xml中,java中也很少出错。请帮帮我。谢谢