Calender View shows Utility declaration error

200 views Asked by At

The following code shows error about Utility declaration and Array Adapter Class....

I have added Some more code to it....

==================================================================================

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Locale;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


  public class CalendarView extends Activity {

    public GregorianCalendar month, itemmonth;// calendar instances.

    public CalendarAdapter adapter;// adapter instance
    public Handler handler;// for grabbing some event values for showing the dot
                            // marker.
    public ArrayList<String> items; // container to store calendar items which
                                    // needs showing the event marker
    ArrayList<String> event;
    LinearLayout rLayout;
     ArrayList<String> date;
     ArrayList<String> desc;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar);
         Locale.getDefault();   // Locale.setdefault(Locale.US);

        rLayout = (LinearLayout) findViewById(R.id.singleItem);
        month = (GregorianCalendar) GregorianCalendar.getInstance();
        itemmonth = (GregorianCalendar) month.clone();

        items = new ArrayList<String>();
        adapter = new CalendarAdapter(this, month);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(adapter);

        handler = new Handler();
        handler.post(calendarUpdater);

        TextView title = (TextView) findViewById(R.id.title);
        title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));

        RelativeLayout previous = (RelativeLayout) findViewById(R.id.previous);

        previous.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setPreviousMonth();
                refreshCalendar();
            }
        });

        RelativeLayout next = (RelativeLayout) findViewById(R.id.next);
        next.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setNextMonth();
                refreshCalendar();

            }
        });

        gridview.setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) 
            {
                // removing the previous view if added
                if (((LinearLayout) rLayout).getChildCount() > 0)
                {
                    ((LinearLayout) rLayout).removeAllViews();
                }
                desc = new ArrayList<String>();
                date = new ArrayList<String>();
                ((CalendarAdapter) parent.getAdapter()).setSelected(v);
                String selectedGridDate = CalendarAdapter.dayString
                        .get(position);
                String[] separatedTime = selectedGridDate.split("-");
                String gridvalueString = separatedTime[2].replaceFirst("^0*",
                        "");// taking last part of date. ie; 2 from 2012-12-02.
                int gridvalue = Integer.parseInt(gridvalueString);
                // navigate to next or previous month on clicking offdays.
                if ((gridvalue > 10) && (position < 8))
                {
                    setPreviousMonth();
                    refreshCalendar();
                } else if ((gridvalue < 7) && (position > 28))
                {
                    setNextMonth();
                    refreshCalendar();
                }
                ((CalendarAdapter) parent.getAdapter()).setSelected(v);

// Error shows here About Utility and ArrayAdapter Error.

                for (int i = 0; i < Utility.startDates.size(); i++) 
                {
                    if (Utility.startDates.get(i).equals(selectedGridDate)) 
                    {
                        desc.add(Utility.nameOfEvent.get(i));
                    }
                }

            final Dialog dialog = new Dialog(CalenderView.this);
            dialog.setContentView(R.layout.list_layout);
            dialog.setTitle("Events");
            ListView listView = (ListView) dialog.findViewById(R.id.list);

            ArrayAdapter<String> ad = new ArrayAdapter<String>(this, R.layout.single_item_layout ,  desc);//desc your string array 
            listView.setAdapter(ad);

            listView.setOnItemClickListener(new OnItemClickListener()
            {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
                {
                    //do something on click
                    dialog.dismiss();
                }
            });

            dialog.show();
        }   
       desc=null;

    });
}
0

There are 0 answers