android how to write drag n drop for my given application
<p>I have done todo list application. All aree did but one extra thing I want to do, in my app HomeActivity contains tasks as listview(single item consists a checkbox, a textview, a imageview) I want drag n drog of items. 
Externaly how to do drag n drop I got but I want to add that into my codes. Please gothrough my code I given below &amp; suggest me where I made change for drag n drop.</p>

<h2>DBAdapter.java(Database)</h2>

<p>package com.v3.todo;</p>

<p>import android.R.string;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;</p>

<p>public class DBAdapter {
    // Initial Configuration
    public static final String DB_NAME = "To-Do";
    private static final int DATABASE_VER = 2;
    private static final String TAG = "DBAdapter";</p>

<pre><code>private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;

// Set the Tables Key Words
public static final String TABLE_TASKS = "tasks";

// Table Queries
private static final String CREATE_TASKS = "CREATE TABLE tasks (_id INTEGER PRIMARY KEY AUTOINCREMENT, todo TEXT, date_create TEXT, date_completed TEXT, completed INTEGER, orderId INTEGER NOT NULL);";

// Keys
public static final String ID = "_id";
public static final String KEY_TODO = "todo";
public static final String KEY_DATECREATE = "date_create";
public static final String KEY_DATECOMPLETED = "date_completed";
public static final String KEY_COMPLETED = "completed";
public static final String KEY_ORDER = "orderId";

public DBAdapter(Context ctx) {
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper {

    public DatabaseHelper(Context context) {
        super(context, DB_NAME, null, DATABASE_VER);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TASKS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS Tasks");
        onCreate(db);
    }

}

public DBAdapter open() throws SQLException {
    db = DBHelper.getWritableDatabase();

    return this;
}

public void close() {
    DBHelper.close();
}

// Custom Methods

// Insert data to Task table
public long insertINtask(String taskNm, String dtCreate, String dtComplete,
        int completed, int order) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_TODO, taskNm);
    initialValues.put(KEY_DATECREATE, dtCreate);
    initialValues.put(KEY_DATECOMPLETED, dtComplete);
    initialValues.put(KEY_COMPLETED, completed);
    initialValues.put(KEY_ORDER, order);
    return db.insert(TABLE_TASKS, null, initialValues);
}

// Get Last priority
public int getLastPriority() {
    int maxOrder = 0;
    boolean flag = false;
    Cursor cr=null;
    try{
    cr = db.rawQuery("select max(" + KEY_ORDER + ") from "
            + TABLE_TASKS, null);
    cr.moveToFirst();
    System.out.println("rawQuery: " + "select max(" + KEY_ORDER + ") from "
            + TABLE_TASKS);
    System.out.println("Max order= " + cr.getString(0));
    if (cr.getString(0) == null)
        maxOrder = 0;
    else
        maxOrder = Integer.parseInt(cr.getString(0));
    } catch (Exception ex) {
        System.out.println("Within DBAdapter " + ex.toString());
    } finally {
        cr.close();
    }
    return maxOrder;

}

// Get Uncompleted Tasks
public Cursor getUncompletedTask() {
    Cursor c = db.query(TABLE_TASKS, new String[] { ID, KEY_TODO },
            KEY_COMPLETED + "= 0", null, null, null, null, null);
    c=db.query(TABLE_TASKS, new String[]{ID,KEY_TODO},KEY_COMPLETED + "= 0", null, null, null, KEY_ORDER + " ASC" ,null);
    return c;
}

// Get Completed Tasks
public Cursor getCompletedTask() {
    return db.query(TABLE_TASKS, new String[] { ID, KEY_TODO },
            KEY_COMPLETED + "= 1", null, null, null, null, null);
}

// Get Task Id
public Cursor getTask_ID(String taskNm) {
    return db.query(TABLE_TASKS, new String[] { ID, KEY_TODO }, KEY_TODO
            + "= '" + taskNm + "'", null, null, null, null, null);
}

// Get Task-Name
public Cursor getTask_Name(int TID) {
    return db.query(TABLE_TASKS, new String[] { ID, KEY_TODO }, ID + "= "
            + TID, null, null, null, null, null);
}

//Get Order
public Cursor getOrder(int TID) {
    return db.query(TABLE_TASKS, new String[] { ID, KEY_ORDER }, ID + "= "
            + TID, null, null, null, null, null);
}
// Edit Task-Name
public boolean updateTaskNm(int TID, String taskNm) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_TODO, taskNm);
    return db.update(TABLE_TASKS, initialValues, ID + "=" + TID, null) &gt; 0;
}

// Delete a record
public boolean deleteTask(int TID) {
    return db.delete(TABLE_TASKS, ID + "=" + TID, null) &gt; 0;
}

// Make Unmark to a task
public boolean unMarkTask(int TID,String dtCreate) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_COMPLETED, 0);
    initialValues.put(KEY_DATECREATE, dtCreate);
    return db.update(TABLE_TASKS, initialValues, ID + "=" + TID, null) &gt; 0;
}

// Set Task complete
public boolean setTaskComplete(int TID, String dtComplete) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_COMPLETED, 1);
    initialValues.put(KEY_DATECOMPLETED, dtComplete);
    return db.update(TABLE_TASKS, initialValues, ID + "=" + TID, null) &gt; 0;
}

//Update Order
public boolean setOrder(int OId,int TID) {
    System.out.println("==== OID="+OId+" TID="+TID);
    if(db==null)
        db = DBHelper.getWritableDatabase();

    if(!db.isOpen())
        open();

    boolean f=false;
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_ORDER, OId);
    db.execSQL("update "+TABLE_TASKS+" set "+KEY_ORDER+"="+OId+" where _id="+TID);
    //f= db.update(TABLE_TASKS, initialValues, ID + "=" + TID, null) &gt; 0;

    return f;
}
//Get orders between--Not used
public Cursor getBetweenOrders(int fOrder,int tOrder) {
    return db.query(TABLE_TASKS, new String[] { ID, KEY_ORDER }, KEY_ORDER + " BETWEEN "+fOrder +" AND "+tOrder, null, null, null, null, null);
}

//Update all orders--not used
public boolean setAllOrders(int[] TID, int[] orderid,int count) {
    boolean f=false;
    ContentValues initialValues = new ContentValues();
    for(int i=0;i&lt;count;i++)
    {
        initialValues.put(KEY_ORDER, orderid[i]);
        f= db.update(TABLE_TASKS, initialValues, ID + "=" + TID[i], null) &gt; 0;
    }
    return f;
}
</code></pre>

<p>}</p>

<h2>HomeActivity.java</h2>

<p>package com.v3.todo;</p>

<p>import java.util.ArrayList;
import java.util.Calendar;</p>

<p>import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;</p>

<p>public class HomeActivity extends ListActivity {
    DBAdapter db;
    Cursor cr;
    CheckBox[] chk;
    static String[] valChk;
    static int Task_Id, taskId;
    static int[] idchk;
    EditText edTask;
    Button btnAdd;
    String newTask = "";
    int order;
    Calendar c = Calendar.getInstance();
    private int mYear, mMonth, mDay, mHour, mMinute;
     static final int TIME_DIALOG_ID = 0, DATE_DIALOG_ID = 1;</p>

<pre><code>String date = "", time = "", dateTime = "";
// ArrayList al = new ArrayList();
static ArrayList&lt;Task&gt; m_tasks = new ArrayList&lt;Task&gt;(), t_tasks = null;
TaskAdapter m_adapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.setTitle("To-Do Lists");

    btnAdd = (Button) findViewById(R.id.btnAdd);
    edTask = (EditText) findViewById(R.id.etAddTask);
    edTask.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == true) {
                if (edTask.getText().toString()
                        .compareTo("Add task here...") == 0) // default text
                {
                    edTask.setText("");
                }
            }
        }
    });

    db = new DBAdapter(HomeActivity.this);
    m_tasks = getTasks();

    if (m_tasks.size() != 0) {
        this.m_adapter = new TaskAdapter(this, R.layout.addchecktomain,
                m_tasks);
        // lv1.setAdapter(this.m_adapter);
        System.out.println("creating");
        setListAdapter(this.m_adapter);
    } else {

        RelativeLayout rl = (RelativeLayout) findViewById(R.id.layout);
        TextView tv = new TextView(this);
        tv.setText("No To-Do Lists");
        tv.setTextSize(22);
        rl.addView(tv);
    }
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
        mHour = c.get(Calendar.HOUR_OF_DAY);
        mMinute = c.get(Calendar.MINUTE);


    btnAdd.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            newTask = edTask.getText().toString();

            String min = Integer.toString(c.get(Calendar.MINUTE));
            String hr = Integer.toString(c.get(Calendar.HOUR));
            String dd = Integer.toString(c.get(Calendar.DATE));
            String mm = Integer.toString(c.get(Calendar.MONTH));
            String yyyy = Integer.toString(c.get(Calendar.YEAR));
            if (min.length() == 1)
                min = "0" + min;
            if (hr.length() == 1)
                hr = "0" + hr;
            if (dd.length() == 1)
                dd = "0" + dd;
            if (mm.length() == 1)
                mm = "0" + mm;
            String dtCreate = mm + "-" + dd + "-" + yyyy + " " + hr + ":"
                    + min;
            if (newTask.equals("")) {
                alertboxNeutral("Warning", "Task should not be empty!",
                        "Okay");
            }
            else if (newTask.length() &lt; 2) {
                alertboxNeutral("Warning",
                        "Task should not be less than 2 Letters", "Okay");
            } else {
                try {
                    db.open();
                    long id1;
                    order = db.getLastPriority();
                    if (order == 0)
                        id1 = db.insertINtask(newTask, dtCreate, null, 0, 1);
                    else
                        id1 = db.insertINtask(newTask, dtCreate, null, 0,
                                order + 1);

                } catch (Exception ex) {
                    System.out.println("Within AddTask HomeActivity " + ex.toString());
                } finally {
                    db.close();
                }
                alertboxNeutral("Success", "Saved.", "Okay");
            }
        }
    });
}

// Method to fetch Uncompleted tasks from db with ID
public ArrayList&lt;Task&gt; getTasks() {
    t_tasks = new ArrayList&lt;Task&gt;();
    try {
        db.open();
        cr = db.getUncompletedTask();
        if (cr.moveToFirst()) {
            do {
                Task t1 = new Task();
                String[] str = new String[2];
                str[0] = cr.getString(0);
                str[1] = cr.getString(1);
                t1.setTaskID(cr.getString(0));
                t1.setTaskName(cr.getString(1));
                t_tasks.add(t1);
            } while (cr.moveToNext());
        }
    } catch (Exception ex) {
        System.out.println("Within Home " + ex.toString());
    } finally {
        cr.close();
        db.close();
    }

    return t_tasks;
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    menu.setHeaderTitle("Task");
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
    System.out.println("v.getId=" + v.getId());
    Task_Id = (Integer) v.getTag();

}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
            .getMenuInfo();

    switch (item.getItemId()) {
    case R.id.edit_task:
        Intent i1 = new Intent(HomeActivity.this, EditTaskActivity.class);
        i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i1);

        return true;
    case R.id.delete_task:
        // database functions
        boolean f = false;
        try {
            db.open();
            f = db.deleteTask(Task_Id);
        } catch (Exception ex) {
            System.out.println("Within Home " + ex.toString());
        } finally {
            db.close();
        }
        if (f == true)
            alertboxNeutral("Success", "Deleted.", "Okay");
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

public void alertboxNeutral(String title, String message, String positive) {
    AlertDialog.Builder alertbox = new AlertDialog.Builder(
            HomeActivity.this);
    if (title.equals("Warning")) {
        alertbox.setTitle(title);
        alertbox.setMessage(message);
        alertbox.setPositiveButton(positive,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent i = new Intent(HomeActivity.this,
                                HomeActivity.class);
                        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(i);
                    }
                });
        alertbox.show();
    } else if (title.equals("Success")) {
        alertbox.setTitle(title);
        alertbox.setMessage(message);
        alertbox.setPositiveButton(positive,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent i = new Intent(HomeActivity.this,
                                HomeActivity.class);
                        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(i);
                    }
                });
        alertbox.show();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.add_task:
        Intent i1 = new Intent(this, AddTaskActivity.class);
        i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i1);
        break;
    case R.id.list_completed:
        Intent i2 = new Intent(this, ListCompletedActivity.class);
        i2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i2);
        break;
    case R.id.rearrange:
        Intent i3 = new Intent(this, RearrangeActivity.class);
        i3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i3);
        break;
    case R.id.exit:
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        break;
    }

    return true;
}

/*
 * @Override protected void onPause() { // TODO Auto-generated method stub
 * super.onPause(); finish(); }
 */

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    try {
        db.open();
        m_tasks = getTasks();
    } catch (Exception ex) {
        System.out.println("Within Home " + ex.toString());
    } finally {
        db.close();
    }
    m_adapter = new TaskAdapter(this, R.layout.addchecktomain, m_tasks);

    System.out.println("notify data changed");
    // m_adapter.notifyDataSetInvalidated();
    // m_adapter.notifyDataSetChanged();
    setListAdapter(this.m_adapter);
    super.onResume();

}

/*
 * @Override public void onBackPressed() { // TODO Auto-generated method
 * stub db.open(); m_tasks = getTasks(); db.close();
 * System.out.println("notify data changed on back pressed");
 * m_adapter.notifyDataSetInvalidated(); m_adapter.notifyDataSetChanged();
 * super.onBackPressed(); }
 */
 @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case TIME_DIALOG_ID:
                return new TimePickerDialog(this,
                        mTimeSetListener, mHour, mMinute, false);
            case DATE_DIALOG_ID:
                return new DatePickerDialog(this,
                            mDateSetListener,
                            mYear, mMonth, mDay);
        }
        return null;
    }
 @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        switch (id) {
            case TIME_DIALOG_ID:
                ((TimePickerDialog) dialog).updateTime(mHour, mMinute);
                break;
            case DATE_DIALOG_ID:
                ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
                break;
        }
    }    

private void updateDisplay() {
    //edTask.setText(new StringBuilder().append(mMonth + 1).append("-").append(mDay).append("-").append(mYear).append(" ").append(pad(mHour)).append(":").append(pad(mMinute)));

    c.setTimeInMillis(System.currentTimeMillis());
    c.clear();
    c.set(Calendar.YEAR, mYear);
    c.set(Calendar.MONTH, mMonth);
    c.set(Calendar.DAY_OF_MONTH, mDay);
    c.set(Calendar.HOUR, mHour);
    c.set(Calendar.MINUTE, mMinute);
    Intent activate = new Intent(this, getClass());
    AlarmManager alarams ;//=  (AlarmManager) this.getSystemService(ALARM_SERVICE);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
    alarams = (AlarmManager) getSystemService(this.ALARM_SERVICE);
    alarams.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), alarmIntent);

    /*Intent intent = new Intent(this, MyBroadcastReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
            this.getApplicationContext(), 234324243, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis()
            + (10 * 1000), pendingIntent);*/
    Toast.makeText(this, "Alarm set in 10 seconds", Toast.LENGTH_LONG).show();


}

    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year, int monthOfYear,
                        int dayOfMonth) {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    updateDisplay();
                }
            };

    private TimePickerDialog.OnTimeSetListener mTimeSetListener =
            new TimePickerDialog.OnTimeSetListener() {

                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    mHour = hourOfDay;
                    mMinute = minute;
                    updateDisplay();
                }
            };

    private static String pad(int c) {
        if (c &gt;= 10)
            return String.valueOf(c);
        else
            return "0" + String.valueOf(c);
    }
</code></pre>

<p>}</p>

<h2>Task.java</h2>

<p>//Class for getting value from HomeActivity and set into the two variables</p>

<p>package com.v3.todo;</p>

<p>public class Task {
String TaskNm;
String TaskId;</p>

<p>public String getTaskName() {
    return TaskNm;
}
public void setTaskName(String TaskNm) {
    this.TaskNm = TaskNm;
}
public String getTaskId() {
    return TaskId;
}
public void setTaskID(String TaskId) {
    this.TaskId=TaskId;
}
}</p>

<h2>TaskAdapter.java</h2>

<p>package com.v3.todo;</p>

<p>import java.util.ArrayList;
import java.util.Calendar;</p>

<p>import com.v3.todo.DragNDropAdapter.ViewHolder;</p>

<p>import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;</p>

<p>public final class TaskAdapter extends ArrayAdapter {
    ArrayList tasks;
    Context context1;
    CheckBox chk;
    TextView tv;
    ImageView imgAlram;
    DBAdapter db;
    static int TaskId;
    static int RId;
    Calendar c = Calendar.getInstance();
    boolean f = false;
    private int mYear, mMonth, mDay, mHour, mMinute;
    static final int TIME_DIALOG_ID = 1, DATE_DIALOG_ID = 0;
    String date = "", time = "", dateTime = "";</p>

<pre><code>public TaskAdapter(Context context, int textViewResourceId,
        ArrayList&lt;Task&gt; tasks) {
    super(context, textViewResourceId, tasks);
    this.tasks = tasks;
    context1 = context;
    RId = textViewResourceId;
}

public int getCount() {
    return tasks.size();
}

public Task getItem(int position) {
    return tasks.get(position);
}

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

public View getView(int position, View convertView, ViewGroup parent) {
    final int pos = position;
    final int dbid;
    View v = convertView;
    ViewHolder holder;
    Task t = tasks.get(position);

    if (v == null) {
        LayoutInflater vi = (LayoutInflater) context1
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.addchecktomain, null);

        holder = new ViewHolder();
        //holder.text = (TextView) v.findViewById(t.getTaskId());
        v.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            System.out.println(convertView.getTag());
            holder = (ViewHolder) convertView.getTag();
        }

    if (t != null) {
        chk = (CheckBox) v.findViewById(R.id.cboTask);
        tv = (TextView) v.findViewById(R.id.tvTask);
        imgAlram = (ImageView) v.findViewById(R.id.imageAlram);

        if (chk != null) {
            chk.setId(Integer.parseInt(t.getTaskId()));

            chk.setText("");
            // chk.setTag(Integer.parseInt(t.getTaskId()), t.getTaskName());

            chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    int taskId = buttonView.getId();
                    if (isChecked) {
                        // /call setTaskComplete(i)
                        // / reset list view or refresh list view
                        String min = Integer.toString(c
                                .get(Calendar.MINUTE));
                        String hr = Integer.toString(c.get(Calendar.HOUR));
                        String dd = Integer.toString(c.get(Calendar.DATE));
                        String mm = Integer.toString(c.get(Calendar.MONTH));
                        String yyyy = Integer.toString(c.get(Calendar.YEAR));
                        if (min.length() == 1)
                            min = "0" + min;
                        if (hr.length() == 1)
                            hr = "0" + hr;
                        if (dd.length() == 1)
                            dd = "0" + dd;
                        if (mm.length() == 1)
                            mm = "0" + mm;
                        String dtComplete = mm + "-" + dd + "-" + yyyy
                                + " " + hr + ":" + min;
                        try {
                            db = new DBAdapter(context1);
                            db.open();
                            f = db.setTaskComplete(taskId, dtComplete);
                        } catch (Exception ex) {
                            System.out.println("Within Home "
                                    + ex.toString());
                        } finally {
                            db.close();
                        }
                        if (f == true) {
                            // HomeActivity.referesh = 1;
                            Intent intent = new Intent(context1,
                                    HomeActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            // HomeActivity.
                            context1.startActivity(intent);
                            Toast.makeText(context1, "Task Completed",
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                }
            });
        }
        if (tv != null) {
            tv.setText(t.getTaskName());
            dbid = Integer.parseInt(t.getTaskId());
            tv.setTag(dbid);

            tv.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    Toast.makeText(
                            context1,
                            "You have chosen the task: " + " "
                                    + v.getTag().toString() + "  Id: "
                                    + dbid + "::" + pos, Toast.LENGTH_LONG)
                            .show();
                    tv.setHighlightColor(android.graphics.Color.RED);
                }
            });
            ((Activity) context1).registerForContextMenu(tv);
        }
        if (imgAlram != null) {
            imgAlram.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    // Write ur code here
                    Toast.makeText(context1, "You have chosen the Alram ",
                            Toast.LENGTH_LONG).show();
                    ((Activity) context1).showDialog(DATE_DIALOG_ID);
                    ((Activity) context1).showDialog(TIME_DIALOG_ID);
                }
            });
        }
    }
    return v;
}

static class ViewHolder {
    TextView text;
}
</code></pre>

<p>}</p>

<h2>mai.xml</h2>

<p>
−



−




</p>

<h2>addchecktomain.xml</h2>

<p>
−

−

−







</p>

<p>Change required for HomeActivity &amp; TakAdapter.java (getView())
Please tell me in my above application what should be write so that listitems can drag n drop .
Thanx</p>
