2014-02-22 43 views
8

在Google Stock Android日历中存在多个视图(月,周,议程,周),从Google Android Sources Repositories下载的源代码具有相同的应用程序,通过探索代码包命名com.android.calendar有负责渲染这些活动的主要观点:如何在自定义应用中使用Android股票日历(月,日,星期)

enter image description here

硬代码周围的工作,我用了两个包com.android.calendar.monthcom.android.calendar,但不能达到我的目标,这是我用过的一个样本:

enter image description here

和主下面的代码:

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

,这里是我的XML代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/month" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:paddingTop="1dip" 
    android:background="@null"> 

    <TextView android:id="@+id/month_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dip" 
     android:visibility="gone" 
     style="@style/MonthView_MiniMonthLabel" /> 

    <include android:id="@+id/day_names" layout="@layout/full_month_header" /> 

    <View 
     android:background="@color/calendar_grid_line_inner_vertical_color" 
     android:layout_height="1px" 
     android:layout_width="match_parent" /> 

    <com.android.calendar.month.MonthListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:drawSelectorOnTop="false" /> 

</LinearLayout> 

到这里的代码工作正常,但有一个空白屏幕和一个操作栏,如果我的问题不明确,请尝试编辑它。

What should be done to include Calendar Views (Month, Week, Day) in a custom application ? 
+0

你有什么需要吗?除了简单的选择日期之外,还有什么? –

+0

你是否知道这个问题? –

+0

@MouhamadLamaa不,我还没有到现在 –

回答

2

您应该看看CalendarView这是在Android中集成日历的标准方式。

此外,如果您需要选择日期&您的用户界面中的时间,有DatePickerTimePicker

请记住,Android中的默认日历应用程序是开源!请随时致电dig through the code here

+0

但我的意思是在图片中发现的视图 –

+0

我看到三个屏幕截图,其中包含许多不同的视图元素。哪一个是你正在寻找的? – donfuxx

+0

我正在寻找右边的第三张照片,我怎么能够实现这个观点? @donfuxx –

1

由于您尚未为ListView设置适配器,因此屏幕为空白。您可以在MonthByWeekFragment中看到原始日历应用程序中的适配器是如何配置的。

@Override 
    protected void setUpAdapter() { 
     mFirstDayOfWeek = Utils.getFirstDayOfWeek(mContext); 
     mShowWeekNumber = Utils.getShowWeekNumber(mContext); 

     HashMap<String, Integer> weekParams = new HashMap<String, Integer>(); 
     weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_NUM_WEEKS, mNumWeeks); 
     weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_SHOW_WEEK, mShowWeekNumber ? 1 : 0); 
     weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_WEEK_START, mFirstDayOfWeek); 
     weekParams.put(MonthByWeekAdapter.WEEK_PARAMS_IS_MINI, mIsMiniMonth ? 1 : 0); 
     weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_JULIAN_DAY, 
      Time.getJulianDay(mSelectedDay.toMillis(true), mSelectedDay.gmtoff)); 
     weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_DAYS_PER_WEEK, mDaysPerWeek); 
     if (mAdapter == null) { 
      mAdapter = new MonthByWeekAdapter(getActivity(), weekParams, mEventDialogHandler); 
      mAdapter.registerDataSetObserver(mObserver); 
     } else { 
      mAdapter.updateParams(weekParams); 
     } 
     mAdapter.notifyDataSetChanged(); 
    } 

和适配器是如何addded到ListView在SimpleDayPickerFragment

@Override 
public void onAttach(Activity activity) { 
    ... 

    setUpAdapter(); 
    setListAdapter(mAdapter); 
} 
相关问题