问题描述
我想开发一个自定义日历日视图为Android OS 1.5及更高版本上。
I want to develop a custom calendar day view for android OS 1.5 and later on.
类似Android的一天日历事件添加和放大器;在日视图中显示。
Similar to android day calendar and event add & display in day view.
如果你有例子或它的来源,那么请给我。
If you have example or source of it then please give me.
我不知道如何下手。请指引我。
I have no idea how to start. Please guide me.
我做月视图按以下链接:
I have done month view as per below link:
HTTP://w2davids.word$p$pss.com/android - 简单日历/
但我也必须创建日视图,请帮助我。
but I have to also create day view so please help me.
我要显示这样的:
推荐答案
我只是工作的内容:
I just worked on this:
您可能认为这是一个的的蓝图,启动的
You could consider it a blueprint to start
小问题的:谁能告诉我whereI可以发布自己的教程之类的东西?什么是最好的网站或某事? (我不想付出我自己的网站,虽然它是一个很酷的想法)
small question: can someone tell me whereI could post my own tutorials and stuff? what is the nicest site or sth? (I dont want to pay for my own site although its a cool idea)
/**
* @author Sherif
*
* Copyright 2011
*
* Sample Day Viewer that will show entries of each hour with ability to
* add events and stuff
* You should find a way to keep a container that will keep track of added events
*
*/
public class DayViewActivity extends ListActivity {
/** Called when the activity is first created. */
private static int HOURS_PER_DAY = 24;
Context mContext = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getListView().setBackgroundColor(Color.rgb(12, 12, 12));
getListView().setDividerHeight(0);
setListAdapter(new ListAdapter(){
@Override
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEnabled(int arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return HOURS_PER_DAY;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getItemViewType(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater inflater = getLayoutInflater();
View listItem = (View) inflater.inflate(R.layout.list_item, getListView(),false);
TextView hourTV = (TextView) listItem.findViewById(R.id.hourTV);
TextView amTV = (TextView) listItem.findViewById(R.id.amTV);
hourTV.setTextColor(Color.BLUE);
amTV.setTextColor(Color.BLUE);
final LinearLayout eventsLL = (LinearLayout) listItem.findViewById(R.id.eventsLL);
hourTV.setText(String.valueOf((position+9)%24));
//I set am/pm for each entry ... you could specify which entries
if(((position>=0)&&(position<=2))||((position>=15)&&(position<=23)))
amTV.setText("am");
else
amTV.setText("pm");
eventsLL.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
alert.setTitle("New Event");
alert.setMessage("Event:");
// Set an EditText view to get user input
final EditText input = new EditText(mContext);
alert.setView(input);
alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
TextView A = new TextView(mContext);
A.setText(input.getText());
A.setTextColor(Color.BLACK);
eventsLL.addView(A);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
});
return listItem;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 1;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void registerDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
});
}
/绘制/ eventbg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<corners android:radius="5px"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
/布局/ list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:background="#CCC">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/hourTV"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView
android:id="@+id/amTV"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="@+id/LLdesign"
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="3dip">
<LinearLayout
android:id="@+id/eventsLL"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/eventbg"></LinearLayout>
</LinearLayout>
</LinearLayout>
这篇关于在Android的自定义日历dayview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!