Android的CalendarView不显示天 [英] Android CalendarView not displaying the days
问题描述
我一直在使用的Android CalendarView得到一个预约管理器应用程序在我的屏幕上显示的日历。
在我的情况,到目前为止,应用程序用户可以通过选择创建约会按钮创建一个约会,我打算显示日历来选择三个或四个文本输入框沿日期。
但我倾向于总是只得到CalendarView月,年和一周的日子标题而不是一个月的天列表。我很困惑,无论是我使用抑或是某些其他原因涉及到的布局问题。
以下是相关类和布局文件的源$ C $ C。
I have been using Android CalendarView to get a Calendar displayed on my screen in a Appointment Manager Application. In my case so far, the app user will be able to create an appointment by selecting the Create an appointment button and I intend to display a Calendar to select a date along with three or four text inputs. But I tend to always get only the CalendarView month, year and the headings of the week's days but not the list of days of the month. I am confused whether it is an issue related to the layout I am using or whether it is some other reason. The following are the source code of the related class and layout file.
CreateAppointmentActivity.java
CreateAppointmentActivity.java
package lk.iit.appointmentmanagerapp.activities;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.Toast;
import android.widget.CalendarView.OnDateChangeListener;
public class CreateAppointmentActivity extends Activity {
CalendarView calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_appointment);
this.initializeCalendar();
}
public void initializeCalendar() {
calendar = (CalendarView) findViewById(R.id.calendar);
calendar.setShowWeekNumber(false);
calendar.setFirstDayOfWeek(2);
calendar.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int day) {
Toast.makeText(getApplicationContext(), day + "/" + month + "/" + year, Toast.LENGTH_LONG).show();
}
});
}
}
activity_create_appointment.xml
activity_create_appointment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/background"
tools:context="lk.iit.appointmentmanagerapp.activities.CreateAppointmentActivity" >
<TextView
android:id="@+id/create_activity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_create"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip"
android:textSize="18.5sp"
android:textColor="#ffffff" />
<CalendarView
android:id="@+id/calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/create_activity_title"
/>
<TextView
android:id="@+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/calendar"
android:layout_marginTop="15dip"
android:text="@string/title_textview_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/edit_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/calendar"
android:layout_marginTop="15dip"
android:layout_toRightOf="@+id/title_textview"
android:layout_marginLeft="30dip"
android:background="#ffffff"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/time_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_textview"
android:layout_marginTop="25dip"
android:text="@string/time_textview_text"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText
android:id="@+id/edit_time"
android:background="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/time_textview"
android:layout_below="@+id/edit_title"
android:layout_marginLeft="25dip"
android:layout_marginTop="25dip"
android:ems="10"
android:inputType="time" />
<TextView
android:id="@+id/details_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/time_textview"
android:text="@string/details_textview_text"
android:layout_marginTop="25dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/edit_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/details_textview"
android:layout_alignBottom="@+id/details_textview"
android:layout_alignLeft="@+id/edit_title"
android:background="#ffffff"
android:ems="10"
android:inputType="text"
android:scrollbars="vertical" >
</EditText>
<Button
android:id="@+id/save_new_appointment_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/details_textview"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
android:layout_centerHorizontal="true"
android:text="@string/save_button_text"
android:textAllCaps="false" />
<Button
android:id="@+id/reset_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/save_new_appointment_button"
android:layout_marginTop="2dip"
android:layout_centerHorizontal="true"
android:text="@string/reset_button_text"
android:textAllCaps="false" />
</RelativeLayout>
我是比较新的Android开发和用户界面设计。任何人都可以请建议我任何解决方案的上述情况?
I am relatively new to Android development and its user interface designing. Can anybody please suggest me any solutions for the above case?
推荐答案
更改布局参数 match_parent
<CalendarView
android:id="@+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_below="@+id/create_activity_title"
/>
这篇关于Android的CalendarView不显示天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!