How To Do Planner/ Business Calendar In Android
I am planning to do calendar which contain dynamic event below date. But i am not getting good sample regarding it. What is exact name call as per image below in android or share s
Solution 1:
Try to implement with GridView
, below code for Gridview Adapter
:
publicclassGridCellAdapterextendsBaseAdapter//implements OnClickListener
{
privatefinal Context _context;
privatefinal List list;
privatestaticfinalintDAY_OFFSET=1;
privatefinal String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct","Nov", "Dec" };
privatefinalint[] daysOfMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
privateint daysInMonth;
privateint currentDayOfMonth;
privateint currentWeekDay;
Calendar calendar;
private Button gridcell;
List objects;
// Days in Current MonthpublicGridCellAdapter(Context context, int textViewResourceId, int month, int year, List objects)
{
super();
this._context = context;
this.list = newArrayList();
this.objects=objects;
Calendarcalendar= 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];
}
privateintgetNumberOfDaysOfMonth(int i)
{
return daysOfMonth[i];
}
public String getItem(int position)
{
return list.get(position);
}
@OverridepublicintgetCount()
{
return list.size();
}
/**
* Prints Month
*
* @param mm
* @param yy
*/privatevoidprintMonth(int mm, int yy)
{
inttrailingSpaces=0;
intdaysInPrevMonth=0;
intprevMonth=0;
intprevYear=0;
intnextMonth=0;
intnextYear=0;
intcurrentMonth= mm - 1;
getMonthAsString(currentMonth);
daysInMonth = getNumberOfDaysOfMonth(currentMonth);
GregorianCalendarcal=newGregorianCalendar(yy, currentMonth, 1);
if (currentMonth == 11)
{
prevMonth = currentMonth - 1;
daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
nextMonth = 0;
prevYear = yy;
nextYear = yy + 1;
}
elseif (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);
}
intcurrentWeekDay= cal.get(Calendar.DAY_OF_WEEK) - 1;
trailingSpaces = currentWeekDay;
if (cal.isLeapYear(cal.get(Calendar.YEAR)))
{
if (mm == 2)
{
++daysInMonth;
}
elseif (mm == 3)
{
++daysInPrevMonth;
}
}
for (inti=0; i < trailingSpaces; i++)
{
list.add(String.valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET) + i) + "-GREY" + "-" + getMonthAsString(prevMonth)+ "-" + prevYear+"-no");
}
// Current Month Daysfor (inti=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 daysfor (inti=0; i < list.size() % 7; i++)
{
list.add(String.valueOf(i + 1) + "-GREY" + "-" + getMonthAsString(nextMonth) + "-" + nextYear+"-no");
}
}
@OverridepubliclonggetItemId(int position)
{
return position;
}
@Overridepublic View getView(finalint position, View convertView, ViewGroup parent)
{
Viewrow= convertView;
if (row == null)
{
LayoutInflaterinflater= (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("-");
Stringtheday= day_color[0];
gridcell.setText(theday.trim());
gridcell.setTag("");
Calendarcalendar= Calendar.getInstance();
calendar.set(Integer.parseInt(day_color[3].trim()), convertMonthToInt(day_color[2].trim())-1, Integer.parseInt(day_color[0].trim()));
intval= 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 (inti=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 (inti=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(newOnClickListener()
{
@OverridepublicvoidonClick(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
{
}
}
elseif(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 (inti=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;
}
publicintgetCurrentDayOfMonth()
{
return currentDayOfMonth;
}
privatevoidsetCurrentDayOfMonth(int currentDayOfMonth)
{
this.currentDayOfMonth = currentDayOfMonth;
}
publicvoidsetCurrentWeekDay(int currentWeekDay)
{
this.currentWeekDay = currentWeekDay;
}
publicintgetCurrentWeekDay()
{
return currentWeekDay;
}
}
screen_gridcell.xml code :
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="60dp"android:layout_height="50dp"android:background="#ffffff"android:orientation="vertical" ><Buttonandroid: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>
Screenshot
Post a Comment for "How To Do Planner/ Business Calendar In Android"