onItemClick and onTouch in gridview operated simultaneously
<p><code>onItemClick</code> and <code>onTouch</code> of <code>Gridview</code> in my application operate simultaneously. My application is a calendar. </p>

<p>I'm trying <code>onTouch</code> for another month, but only <code>onItemClick</code> works. How can I fix it?</p>

<pre><code>package com.example.ok1;

import java.util.ArrayList;
import java.util.Map;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class ToDoCalendarViewMaker {
//final String Tag="States";


public static void makeGrid(Context context, View view, final MyCalendar myCalendar) {
    final String Tag="States"; 
    Log.d(Tag, "ljokj до сюдого  4");
       GridView myGridView;

       final Context myContext;

       View myView;



       myView = view;

       myContext = context;

       myGridView = (GridView) myView.findViewById(R.id.gridView);


       String[] from = { "text", "background" };

       int[] to = { R.id.tvDay, R.id.llDay };

       ArrayList&lt;Map&lt;String, Object&gt;&gt; myData = new ArrayList&lt;Map&lt;String, Object&gt;&gt;();

       myData = (ArrayList&lt;Map&lt;String, Object&gt;&gt;) myCalendar.myData.clone();



       SimpleAdapter sAdapter = new SimpleAdapter(myContext,

                    myData, R.layout.day_layout, from, to);
       Log.d(Tag, "до биндера");

       sAdapter.setViewBinder(new MyViewBinder());
       Log.d(Tag, "после");

       myGridView.setAdapter(sAdapter);

       myGridView.setNumColumns(7);

       myGridView.setVerticalSpacing(5);

       myGridView.setHorizontalSpacing(5);

       myGridView.setOnTouchListener(new MyGridOnTouchListener());



       myGridView.setOnItemClickListener(new OnItemClickListener() {

             @Override

             public void onItemClick(AdapterView&lt;?&gt; parent, View v,int position, long id){
                //*********работа с БД****************
                    // создаем объект для данных
                        ContentValues cv = new ContentValues();
                        DBHelper dbHelper = new DBHelper(myContext);    
                        SQLiteDatabase db = dbHelper.getWritableDatabase();

                        //*********работа с БД****************  
                        Toast.makeText(myContext,

                        "" + myCalendar.returnDateById(position) + " + " + id,

                        Toast.LENGTH_SHORT).show();      
                       String id_for_listtsk=myCalendar.returnDateById(position).toString();
                        //добавляем строку в БД
                        cv.put("data_id", myCalendar.returnDateById(position));
                     //  long rowID = db.insert("mytable", null, cv);
                        Log.d(Tag, "row inserted, ID = ");
                        Cursor c = db.query("mytable", null, null, null, null, null, null);
                    //   logCursor(c);
                        dbHelper.close();
                        Intent intent = new Intent(myContext, ListTsk.class);
                        Log.d(Tag, "==== "+id_for_listtsk);
                        intent.putExtra("dat", id_for_listtsk.toString());
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        myContext.startActivity(intent);
                     //   return false;
                        //************************
                     //   ToDoCalendarActivity.this.finish();
                 }
            private void logCursor(Cursor c) {
                // TODO Auto-generated method stub
                final String Tag="States";

                if (c!=null) {
                    if (c.moveToFirst()) {
                        String str;
                        do {
                            str="";
                            for (String cn: c.getColumnNames())     {
                                str = str.concat(cn + " = " + c.getString(c.getColumnIndex(cn)) + "; ");
                            }
                            Log.d(Tag, str);
                        } while (c.moveToNext());

                    } 
                }



            }


       });

       //sAdapter.notifyDataSetChanged();




}




}

//********************************************************
class MyViewBinder implements SimpleAdapter.ViewBinder {
    int p;
  @Override

 public boolean setViewValue(View view, Object data,

              String textRepresentation) {

       // TODO Auto-generated method stub

       int i;

       switch (view.getId()) {

       // LinearLayout

       case R.id.llDay:

              i = ((Integer) data).intValue();

              if (i == -1)

                  view.setBackgroundResource(R.drawable.another_day);

              else if (i == 0)

                  view.setBackgroundResource(R.drawable.day);

              else if (i == 1)

                  view.setBackgroundResource(R.drawable.weekend);

              else if (i == 2)

                  p=4;//view.setBackgroundResource(R.drawable.today_another_day);

              else if (i == 3)

                  view.setBackgroundResource(R.drawable.today_day);

              else if (i == 4)

                  p=6;//view.setBackgroundResource(R.drawable.today_weekend);

              return true;

       }

       return false;

 }     

}

class MyGridOnTouchListener implements OnTouchListener{


  final String Tag="States";
  @Override
 public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
      Log.d(Tag, "сработал онтач.....");
       // TODO Auto-generated method stub

       if (paramMotionEvent.getAction() == MotionEvent.ACTION_DOWN) {
              Log.d(Tag, "опустил палец");
              ToDoCalendarActivity.touchX1 = paramMotionEvent.getX();
              Log.d(Tag, "x1="+String.valueOf(ToDoCalendarActivity.touchX1));
              ToDoCalendarActivity.touchY1 = paramMotionEvent.getY();

              ToDoCalendarActivity.flag = true;

       }



       if (paramMotionEvent.getAction() == MotionEvent.ACTION_MOVE) {


              ToDoCalendarActivity.touchY2 = paramMotionEvent.getY();

       }



       if (paramMotionEvent.getAction() == MotionEvent.ACTION_UP) {
           ToDoCalendarActivity.touchX2 = paramMotionEvent.getX();
           Log.d(Tag, "x2="+String.valueOf(ToDoCalendarActivity.touchX2));
                Log.d(Tag, "Поднял палец");
                if (ToDoCalendarActivity.flag==true &amp;&amp;

        Math.abs(ToDoCalendarActivity.touchX2 - ToDoCalendarActivity.touchX1)&gt;

         Math.abs(ToDoCalendarActivity.touchY2 - ToDoCalendarActivity.touchY1)){

          if (ToDoCalendarActivity.touchX2&gt;ToDoCalendarActivity.touchX1){
              if ((ToDoCalendarActivity.touchX2-ToDoCalendarActivity.touchX1)&gt;50) {
                  ToDoCalendarActivity.prevMonth();  
              }

           Log.d(Tag, String.valueOf(ToDoCalendarActivity.touchX2-ToDoCalendarActivity.touchX1));
           ToDoCalendarActivity.flag=false;

         } else {
        Log.d(Tag, String.valueOf(ToDoCalendarActivity.touchX1-ToDoCalendarActivity.touchX2));
        if ((ToDoCalendarActivity.touchX1-ToDoCalendarActivity.touchX2)&gt;50) {
          ToDoCalendarActivity.nextMonth();  
      }

        ToDoCalendarActivity.flag=false;

                                                 }

                                          }
           //   ToDoCalendarActivity.flag = false;

       }

       return false;

 }

}
</code></pre>

<p>I need that when I turned another month did not work onItemClick.   </p>
