Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:15:37+00:00 2026-05-28T17:15:37+00:00

I am working with the BaseAdapter Class. I want to Display DatePickerDialog in it.

  • 0

I am working with the BaseAdapter Class. I want to Display DatePickerDialog in it.
When I use showDialog(DATE_DIALOG_ID); I am getting error.

Please guide me regarding this.

package com.OrganisemeePhone.adapter;

import java.util.ArrayList;
import java.util.Vector;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.OpenableColumns;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;




public class TaskFilterAdapter extends BaseAdapter {
    String date, month, year,setdueDate;
    //int dateFormat;
    DatePickerDialog.OnDateSetListener dateListener;

    int myYear, myMonth, myDay;
    int dateFormat;
    int starcount=0;

    public TaskFilterAdapter datedialog;

    viewholder holder;
    LayoutInflater inflator;
    ArrayList<Integer> taskId = new ArrayList<Integer>();
    ArrayList<String> task = new ArrayList<String>();
    ArrayList<String> dueDate = new ArrayList<String>();
    ArrayList<Integer> priority = new ArrayList<Integer>();
    static final int DATE_DIALOG_ID = 0;
    Vector<Boolean> VectorCheckChange = new  Vector<Boolean>(); 
    Vector<Object> taskrow = new Vector<Object>();  

    static int pos;
    Context context;
    private boolean isdaymonth;
    public TaskFilterAdapter(Context context,ArrayList<Integer> taskId, ArrayList<String> task, ArrayList<Integer> priority, ArrayList<String> duedate) {
        super();

        inflator = LayoutInflater.from(context);
        this.taskId = taskId;
        this.context=context;

        this.task = task;
        this.dueDate = duedate;
        this.priority = priority;

        //dateFormat=LoginActivity.db.getdateformat();
        getDateFormate();
        dateFormat=LoginActivity.db.getdateformat();
        getDateFormate();
        for(int i=0; i<task.size(); i++)
        {
            VectorCheckChange.add(false);
        }
    }


    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return task.size();
    }

    @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 View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null)
        {
            holder = new  viewholder();
            convertView = inflator.inflate(R.layout.task_row, null);
            holder.task = (TextView)convertView.findViewById(R.id.task_row_text);
            holder.date = (TextView)convertView.findViewById(R.id.task_row_date_text);
            holder.star = (ImageView)convertView.findViewById(R.id.task_row_star);
            holder.chk = (CheckBox)convertView.findViewById(R.id.task_row_check_box);

            holder.task.setOnClickListener(new Clicker());
            holder.chk.setOnCheckedChangeListener(new Checker());
            holder.star.setOnClickListener(new Clicker());
            holder.date.setOnClickListener(new Clicker());

            setviewAsSettings();

            setviewAsSettings();


            convertView.setTag(holder);


            }
        else
        {
            holder=(viewholder)convertView.getTag();
        }


        pos = position;

        /****************** Set Task *************************/

        holder.task.setText(task.get(position));
        holder.task.setTag(position);
        holder.star.setTag(position);
        holder.date.setTag(position);



        /***************** Set Duedate ***********************/

        setdueDate = dueDate.get(position);

        month = setdueDate.substring(5, 7);
        date = setdueDate.substring(8, 10);



        if (!date.equals("00"))
        {
            if (isdaymonth) 
            if (isdaymonth)
            {
                holder.date.setText(date + "." + month + ".");
                Log.d("taskList Adapter"," date formate day month ");

            } 
            else 
            {
                holder.date.setText(month + "." + date + ".");
                Log.d("taskList Adapter"," date formate month  day");

            }
        } 
        else
        {
            holder.date.setText("");
        }



        /***************** Set Priority ***********************/


                if (priority.get(position).equals(-1) || priority.get(position).equals(0)|| priority.get(position).equals(3)) 
                {

                    holder.star.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.star_low));

                } 
                else if (priority.get(position).equals(2)) 
                {

                    holder.star.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.star_med));
                }
                else if (priority.get(position).equals(1)) 
                {

                    holder.star.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.star_high));
                }




        /******************* Set tag in checkBox ******************************/

        holder.chk.setTag(position);

        if(VectorCheckChange.get(position))
        {
            holder.chk.setChecked(true);
            holder.task.setPaintFlags(holder.task.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            holder.task.setTextColor(Color.parseColor("#848484"));
            holder.date.setPaintFlags(holder.task.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            holder.date.setTextColor(Color.parseColor("#848484"));
            holder.task.setClickable(false);
            holder.task.setEnabled(false);
        }
        else
        {
            holder.chk.setChecked(false);
            holder.task.setPaintFlags(holder.task.getPaintFlags() & ~ Paint.STRIKE_THRU_TEXT_FLAG);
            holder.task.setTextColor(Color.parseColor("#000000"));
            holder.date.setPaintFlags(holder.task.getPaintFlags() & ~ Paint.STRIKE_THRU_TEXT_FLAG);
            holder.date.setTextColor(Color.parseColor("#000000"));
            holder.task.setClickable(true);
            holder.task.setEnabled(true);
        }


        return convertView;
    }
    // updates by nilesh
    public void setviewAsSettings(){
        //check for task setting
        SharedPreferences startup_pref = 
            PreferenceManager.getDefaultSharedPreferences(context);

        Boolean viewpriority=startup_pref.getBoolean("viewpriority", true);
        Boolean viewduedate=startup_pref.getBoolean("viewduedate", true);

            if(!viewpriority){
                holder.star.setVisibility(View.INVISIBLE);
            }               
            if(!viewduedate){
                holder.date.setVisibility(View.INVISIBLE);
            }
        //check for task setting completed
    }

    public class viewholder
    {
        TextView task,date;
        ImageView star;
        CheckBox chk;

    }


    public class Clicker implements OnClickListener
    {


        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub


            int position=(Integer)v.getTag();
            int setPriority = 0;

        if(v.getId() ==  holder.date.getId())
        {


            Log.i("Date Dialog Picker", "Click Date..................... ");

            ((Activity)context).showDialog(DATE_DIALOG_ID); 

        //.showDialog(DATE_DIALOG_ID);


            //.showDialog(DATE_DIALOG_ID);



            }
        dateListener =  new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int yr, int monthOfYear,
                    int dayOfMonth) {
                // TODO Auto-generated method stub
                myYear = yr;
                myMonth = monthOfYear;
                myDay = dayOfMonth;

                }

            };  



        if(v.getId() == holder.task.getId())
        {
            Intent display_int= new Intent(context, DisplyTaskActivity.class);
            display_int.putExtra(constantcode.TASK_ID,taskId.get(position));
            v.getContext().startActivity(display_int);

            Log.i("TaskList Adapter", "Task ....position...... "+holder.star.getTag());
        }


            if(v.getId() == holder.star.getId())
            {

                 if (priority.get(position).equals(-1) || priority.get(position).equals(0) || priority.get(position).equals(3)) 
                   {
                     priority.set(position, 2);
                     setPriority = 2;

                    holder.star.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.star_low));

                    Log.d("TaskList Adapter", "----- Grey ----");
                   } 
                   else if (priority.get(position).equals(2)) 
                   {
                       priority.set(position, 1);
                       setPriority = 1;

                    holder.star.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.star_med));

                    Log.d("TaskList Adapter", "----- Yellow ----");
                   }
                   else if (priority.get(position).equals(1)) 
                   {
                       priority.set(position, 0);
                       setPriority = 0;

                    holder.star.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.star_high));

                    Log.d("TaskList Adapter", "----- Orange ----");
                   }


                  String  updateQuery = "update tbl_tasks set priority =" + setPriority + " where taskId="+ taskId.get(position);
                  LoginActivity.db.execNonQuery(updateQuery);


                   taskrow = LoginActivity.db.getTaskRow(taskId.get(position));

                    if(taskrow.get(2).toString().contains("'"))
                    {
                        taskrow.set(2, taskrow.get(2).toString().replace("'", "''"));
                    }

                    String insertQuery = "insert into tbl_update_tasks(taskId,listId,description,priority,dueDate,reminderId,senderId,receiverId,taskCategoryType,fadeDate,assignedId)values("+ taskrow.get(0) + ","+ taskrow.get(1)+ ",'"+ taskrow.get(2)+ "',"+ taskrow.get(3)+ ",'"+ taskrow.get(4)+ "',"+ taskrow.get(5)+ ","+ taskrow.get(6)+ ","+ taskrow.get(7)+ ",'"+ taskrow.get(8)+ "','"+ taskrow.get(9)+ "',"+ taskrow.get(10)+ ");";
                    LoginActivity.db.execNonQuery(insertQuery);
                   notifyDataSetChanged();
            }

                //Log.w("taskfilterAdapter","position....... "+v.getTag());
        }


    }

      Dialog onCreateDialog(int id){
            switch(id) {
            case DATE_DIALOG_ID:

                return new DatePickerDialog(this.context, dateListener, myYear, myMonth,myDay);

            }

            return null;

        }

    /* public class datedialogclicker extends Activity
    {


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);



            holder.date.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    Log.v("New Class....", "Click OnClick.....");
                    showDialog(DATE_DIALOG_ID); 
                }

            });

            dateListener =  new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int yr, int monthOfYear,
                        int dayOfMonth) {
                    // TODO Auto-generated method stub
                    myYear = yr;
                    myMonth = monthOfYear;
                    myDay = dayOfMonth;

                    }

                };  



        }
         protected Dialog onCreateDialog(int id){
                switch(id) {
                case DATE_DIALOG_ID:

                    return new DatePickerDialog(context, dateListener, myYear, myMonth,myDay);

                }

                return null;

            }
    }*/

    public class Checker implements OnCheckedChangeListener
    {

        @Override
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            // TODO Auto-generated method stub

            int posi=(Integer)buttonView.getTag();

            if(isChecked)
            {
                VectorCheckChange.set(posi, true);              
            }
            else
            {
                VectorCheckChange.set(posi, false);
            }

            notifyDataSetChanged();


        }

    }
    // update by nilesh
    public void getDateFormate() {

        // Get the app's shared preferences
        SharedPreferences startup_pref = PreferenceManager
                .getDefaultSharedPreferences(context);

        // Get the value for the run counter
        isdaymonth = startup_pref.getBoolean(constantcode.ISDAYMONTH, true);
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:15:38+00:00Added an answer on May 28, 2026 at 5:15 pm

    (1)Define this code in BaseAdapter onClick

    ((Activity)AdapterName.this.context).showDialog(DATE_DIALOG_ID);
    

    (2)below code in Activity:

     DatePickerDialog.OnDateSetListener dateListener =  new DatePickerDialog.OnDateSetListener() {
    
                    @Override
                    public void onDateSet(DatePicker view, int yr, int monthOfYear,
                            int dayOfMonth) {
                        // TODO Auto-generated method stub
                        myYear = yr;
                        myMonth = monthOfYear;
                        myDay = dayOfMonth;
    
                    }
    
    
             }; 
    
    
            Calendar cal = Calendar.getInstance();
            myYear = cal.get(Calendar.YEAR);
            myMonth = cal.get(Calendar.MONTH);
            myDay = cal.get(Calendar.DAY_OF_MONTH);
    
    
    protected Dialog onCreateDialog(int id){
                switch(id) {
                case DATE_DIALOG_ID:
    
                    return new DatePickerDialog(ActivityName.this, dateListener, myYear, myMonth, myDay);
    
                }
                return null;
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI Guyz i have created a sectioned custom listview using baseadapter its working fine
Working on an extension that use the new experimental devtools apis. How do you
Working with Json, how can I NSlog only the title in this code: NSDictionary
I am new to android and I am working in an application that want
I am working on a customized list view here is my adapter class public
Working on dom html . I want to convert node value to string: $html
Why is my OnItemClickListener not working? public class UseAdp extends Activity { /** Called
Working on this EF tutorial , I've difficult to understand the meaning of the
Working with python interactively, it's sometimes necessary to display a result which is some
I'm working with lazy loading a Gallery of images (one class for the Gallery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.