0

我打算在日期下面做包含動態事件的日曆。但我沒有得到有關它的好樣品。 什麼是Android中的下圖所示的確切名稱調用或共享一些想法。我有很多apk和與它相關的圖像。 但它背後沒有確切的想法,android是否支持它。我打算在月,周,日明智地展示日曆。 在谷歌搜索很多我寫這個。 它是否支持從2.3到4的所有版本。我已經在上述版本4上看到了一些博客業務日曆支持。 非常感謝您的好意和好點子。如何在android中執行計劃器/業務日曆

enter image description here

+0

@Lefteris任何想法如何做到這一點 –

+0

我猜u需要谷歌日曆 –

回答

10

嘗試與GridView實現,下面的代碼Gridview Adapter

public class GridCellAdapter extends BaseAdapter //implements OnClickListener 
{ 
    private final Context _context; 

    private final List list; 
    private static final int DAY_OFFSET = 1; 
    private final String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct","Nov", "Dec" }; 
    private final int[] daysOfMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 
    private int daysInMonth; 
    private int currentDayOfMonth; 
    private int currentWeekDay; 
    Calendar calendar; 
    private Button gridcell; 

    List objects; 

    // Days in Current Month 
    public GridCellAdapter(Context context, int textViewResourceId, int month, int year, List objects) 
    { 
    super(); 
    this._context = context; 
    this.list = new ArrayList(); 
    this.objects=objects; 
    Calendar calendar = Calendar.getInstance(); 
    setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH)); 
    setCurrentWeekDay(calendar.get(Calendar.DAY_OF_WEEK)); 

    // Print Month 
    printMonth(month, year); 
    } 

    private String getMonthAsString(int i) 
    { 
    return months[i]; 
    } 

    private int getNumberOfDaysOfMonth(int i) 
    { 
    return daysOfMonth[i]; 
    } 

    public String getItem(int position) 
    { 
    return list.get(position); 
    } 

    @Override 
    public int getCount() 
    { 
    return list.size(); 
    } 

    /** 
    * Prints Month 
    * 
    * @param mm 
    * @param yy 
    */ 
    private void printMonth(int mm, int yy) 
    { 
    int trailingSpaces = 0; 
    int daysInPrevMonth = 0; 
    int prevMonth = 0; 
    int prevYear = 0; 
    int nextMonth = 0; 
    int nextYear = 0; 

    int currentMonth = mm - 1; 
    getMonthAsString(currentMonth); 
    daysInMonth = getNumberOfDaysOfMonth(currentMonth); 

    GregorianCalendar cal = new GregorianCalendar(yy, currentMonth, 1); 
    if (currentMonth == 11) 
    { 
    prevMonth = currentMonth - 1; 
    daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth); 
    nextMonth = 0; 
    prevYear = yy; 
    nextYear = yy + 1; 
    } 
    else if (currentMonth == 0) 
    { 
    prevMonth = 11; 
    prevYear = yy - 1; 
    nextYear = yy; 
    daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth); 
    nextMonth = 1; 
    } 
    else 
    { 
    prevMonth = currentMonth - 1; 
    nextMonth = currentMonth + 1; 
    nextYear = yy; 
    prevYear = yy; 
    daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth); 
    } 

    int currentWeekDay = cal.get(Calendar.DAY_OF_WEEK) - 1; 
    trailingSpaces = currentWeekDay; 

    if (cal.isLeapYear(cal.get(Calendar.YEAR))) 
    { 
    if (mm == 2) 
    { 
    ++daysInMonth; 
    } 
    else if (mm == 3) 
    { 
    ++daysInPrevMonth; 
    } 
    } 

    for (int i = 0; i < trailingSpaces; i++) 
    { 
    list.add(String.valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET) + i) + "-GREY" + "-" + getMonthAsString(prevMonth)+ "-" + prevYear+"-no"); 
    } 

    // Current Month Days 
    for (int i = 1; i <= daysInMonth; i++) 
    { 
    if (i == getCurrentDayOfMonth()) 
    { 
    list.add(String.valueOf(i) + "-BLUE" + "-" + getMonthAsString(currentMonth) + "-" + yy+"-yes"); 
    } 
    else 
    { 
    list.add(String.valueOf(i) + "-WHITE" + "-" + getMonthAsString(currentMonth) + "-" + yy+"-no"); 
    } 
    } 

    // Leading Month days 
    for (int i = 0; i < list.size() % 7; i++) 
    { 
    list.add(String.valueOf(i + 1) + "-GREY" + "-" + getMonthAsString(nextMonth) + "-" + nextYear+"-no"); 
    } 
    } 

    @Override 
    public long getItemId(int position) 
    { 
    return position; 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) 
    { 
    View row = convertView; 
    if (row == null) 
    { 
    LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    row = inflater.inflate(R.layout.screen_gridcell, parent, false); 
    } 

    gridcell = (Button) row.findViewById(R.id.calendar_day_gridcell); 

    String[] day_color = list.get(position).split("-"); 
    String theday = day_color[0]; 
    gridcell.setText(theday.trim()); 
    gridcell.setTag(""); 

    Calendar calendar = Calendar.getInstance(); 
     calendar.set(Integer.parseInt(day_color[3].trim()), convertMonthToInt(day_color[2].trim())-1, Integer.parseInt(day_color[0].trim())); 
     int val = calendar.get(Calendar.DAY_OF_WEEK); 


    gridcell.setGravity(Gravity.CENTER); 

    gridcell.setBackgroundResource(R.drawable.cal_box_grey); 

    if (day_color[1].equals("GREY")) 
    { 
    gridcell.setBackgroundResource(R.drawable.cal_box_grey); 
    gridcell.setTextColor(getResources().getColor(R.color.gray)); 
    } 
    if (day_color[1].equals("WHITE")) 
    { 
    gridcell.setBackgroundResource(R.drawable.cal_box);  
    gridcell.setTextColor(getResources().getColor(R.color.purple_dark)); 
    if(val == 1 || val == 7) 
     { 
     gridcell.setBackgroundResource(R.drawable.circle_grey_border);  
     gridcell.setTextColor(getResources().getColor(R.color.lightgray02)); 
     } 
    } 

    for (int i = 0; i < objects.size(); i++) 
    { 
    if(Integer.parseInt(theday)==Integer.parseInt((objects.get(i).day)) 
     && day_color[2].equals(objects.get(i).month)) 
    { 
    gridcell.setTag(objects.get(i).title+":::"+objects.get(i).address+":::"+objects.get(i).image 
     +":::"+objects.get(i).day+":::"+objects.get(i).month+":::"+objects.get(i).year); 
    gridcell.setTextColor(Color.parseColor("#da0078")); 
    } 
    } 

    if (day_color[1].equals("BLUE")&& day_color[4].equals("yes")) 
    { 
    gridcell.setTextColor(Color.parseColor("#ffffff")); 
    gridcell.setBackgroundResource(R.drawable.circle_days_fill); 
    } 

    if (day_color[4].equals("yes")) 
    { 
    gridcell.setTextColor(Color.parseColor("#ffffff")); 
    gridcell.setBackgroundResource(R.drawable.circle_days_fill); 
    } 

    if (day_color[1].equals("BLUE")&& day_color[4].equals("no")) 
    { 
    gridcell.setTextColor(Color.parseColor("#ffffff")); 
    gridcell.setBackgroundResource(R.drawable.circle_days_fill); 
    } 



    for (int i = 0; i < objects.size(); i++) 
    { 
    if(Integer.parseInt(theday)==Integer.parseInt((objects.get(i).day)) 
     && day_color[2].equals(objects.get(i).month)) 
    { 
    if(objects.get(i).rsvp.equals("1")) 
    { 
     gridcell.setTextColor(Color.parseColor("#008000")); 
    } 
    } 
    } 

    gridcell.setOnClickListener(new OnClickListener() 
    { 
    @Override 
    public void onClick(View v) 
    { 
    // TODO Auto-generated method stub 
    String tag [] = list.get(position).toString().split("-"); 
    if(v.getTag().toString().equals("1")) 
    { 
     v.setTag("1"); 
     if(v.getId() == R.id.calendar_day_gridcell) 
     { 
     if (myToolTipInfoWindow == null) 
     { 
     addPurpleToolTipView(v); 
     } 
     else 
     { 
     myToolTipInfoWindow.remove(); 
     myToolTipInfoWindow = null; 
     } 
     } 
     else 
     { 
     } 
    } 
    else if(v.getTag().toString().equals("")) 
    { 
     v.setTag("1"); 
     if(v.getId() == R.id.calendar_day_gridcell) 
     { 
     if (myToolTipInfoWindow == null) 
     { 
     addPurpleToolTipView(v); 
     } 
     else 
     { 
     myToolTipInfoWindow.remove(); 
     myToolTipInfoWindow = null; 
     } 
     } 
     else 
     { 
     } 
    } 
    else 
    { 
     if(v.getId() == R.id.calendar_day_gridcell) 
     { 
     if (myToolTipInfoWindow == null) 
     { 
     addPurpleToolTipView(v); 
     } 
     else 
     { 
     myToolTipInfoWindow.remove(); 
     myToolTipInfoWindow = null; 
     } 
     } 
     else 
     { 
     } 
    } 
    for (int i = 0; i < list.size(); i++) 
    { 
     gridcell.setTextColor(R.color.purple_lite); 
     gridcell.setBackgroundColor(Color.parseColor("#da0078")); 
     String tags [] = list.get(i).toString().split("-"); 
     list.set(i,tags[0]+"-"+tags[1]+"-"+tags[2]+"-"+tags[3]+"-no"); 
    } 
    list.set(position,tag[0]+"-"+tag[1]+"-"+tag[2]+"-"+tag[3]+"-yes"); 
    adapter1.notifyDataSetChanged(); 

    } 
    }); 

    return row; 
    } 

    public int getCurrentDayOfMonth() 
    { 
    return currentDayOfMonth; 
    } 

    private void setCurrentDayOfMonth(int currentDayOfMonth) 
    { 
    this.currentDayOfMonth = currentDayOfMonth; 
    } 

    public void setCurrentWeekDay(int currentWeekDay) 
    { 
    this.currentWeekDay = currentWeekDay; 
    } 

    public int getCurrentWeekDay() 
    { 
    return currentWeekDay; 
    } 
} 

screen_gridcell.xml代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="60dp" 
    android:layout_height="50dp" 
    android:background="#ffffff" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/calendar_day_gridcell" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:button="@drawable/calendar_button_selector" 
     android:gravity="center" 
     android:textSize="13sp" 
     android:textStyle="bold" 
     android:textColor="#FFFFFF" > 
    </Button> 

</RelativeLayout> 

截圖

Calendar View with event

+0

感謝更新。我會檢查 –

+0

manish dubey偉大的工作感謝的人 – Mahesh