开发者

Android Calendar Gridview - How to keep info about every cell in my Calendar?

I'm trying to build a calendar that looks like Android internal Calendar. The thing that I would like to know is how to keep track of every cell in my View.

I have a Gridcell adapter that extends Base Adapter, here is the code:

    public View getView(int position, View convertView, ViewGroup parent)
        {

            int[][] MatrixPointer = new int[5][7];



            View row = convertView;
            if (row == null)
                {
                    LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    row = inflater.inflate(R.layout.calendar_day_gridcell, parent, false);
                }

            // Get a reference to the Day gridcell
            gridcell = (Button) row.findViewById(R.id.calendar_day_gridcell);


            if(position==34||position==6||position==13||position==20||position==27)
            {
                View v=(View) row.findViewById(R.id.right_border);
                v.setVisibility(View.GONE);
            }

            if(position>=7)
            {
                View v;
                v=(View) row.findViewById(R.id.top_border_double);
                v.setVisibility(View.GONE);
            }


            if(position<=27)
            {
                View v=(View) row.findViewById(R.id.bottom_border_double);
                v.setVisibility(View.GONE);v=(View) row.findViewById(R.id.bottom_border);
                v.setVisibility(View.GONE);
            }
            // ACCOUNT FOR SPACING

            Log.d(tag, "Current Day: " + getCurrentDayOfMonth());
            String[] day_color = list.get(position).split("-");
            String theday = day_color[0];
            String themonth = day_color[2];
            String theyear = day_color[3];
            if ((!eventsPerMonthMap.isEmpty()) && (eventsPerMonthMap != null))
                {
                    if (eventsPerMonthMap.containsKey(theday))
                        {
                            num_events_per_day = (TextView) row.findViewById(R.id.num_events_per_day);
                            Integer numEvents = (Integer) eventsPerMonthMap.get(theday);
                            num_events_per_day.setText(numEvents.toString());
                        }
                }

            // Set the Day GridCell
            gridcell.setText(theday);

            gridcell.setTag(theday + "-" + themonth + "-" + theyear);
            Log.d(tag, "Setting GridCell " + theday + "-" + themonth + "-" + theyear + " \n Position: "+position);

            if (day_color[1].equals("GREY"))
                {
                    gridcell.setTextColor(Color.LTGRAY);
                }
            if (day_color[1].equals("WHITE"))
                {
                    gridcell.setTextColor(Color.DKGRAY);
                }
            if (day_color[1].equals("BLUE"))
                {
                    gridcell.setTextColor(getResources().getColor(R.color.static_text_color));

                }
            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;
        }
    @Override
    public void onClick(View v) {

    }
}

When I use onClick method it doesn't do anything let's say for example:

            gridcell.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    gridcell.setText("TESTING");

                }
            });

doesn't update anything to my View when I do some clicking. Tried also setting a click listener outside my class, in my Activity, but same with no result. I want to know every gridcells position and other information (like text, color). When I change gridcell's color inside a function it destroys my design. For example,

     开发者_JS百科       if (day_color[1].equals("BLUE"))
                {                       gridcell.setBackgroundColor(Color.BLUE);

                }

If I do this it messes up my design.

Hope you understand what I mean and take a look to my code.

Thank you! Radu


Please try this:

if (day_color[1].equals("BLUE")) {              
    gridcell.setTextColor(getResources().getColor(R.color.static_text_color));
    gridcell.setBackgroundDrawable(null);
    gridcell.setBackgroundResource(R.drawable.calendar_button_selector_day);
}

You have to remove the background assigned to button in grid cell. And assign your new background drawable resource. I have tried this. It works for me.


<GridView
    android:id="@+id/gv_series"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="1dip"
    android:layout_marginRight="1dip"
    android:horizontalSpacing="1dip"
    android:numColumns="auto_fit"
    android:verticalSpacing="1dip" android:listSelector="@drawable/item_selector">

</GridView>

then, set GridView's background use a color.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜