我有个问题。我无法在日历中检测到事件触摸
我的日历由Gridview创建。
我想将我的日历触摸到图片中的红线
(触摸8并移动到22)但我可以检测到图片中蓝线的事件触摸(触摸3并移至5)
我尝试检查红线的动作是 ACTION_CANCLE 。我不知道为什么会这样。
gridcell.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/laycal">
<TextView
android:id="@+id/txt_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="16sp" >
</TextView>
</LinearLayout>
</LinearLayout>
layout_grid.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<GridView
android:numColumns="7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridcal"
/>
</LinearLayout>
cal_adpter.java
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.gridcell, null);
TextView textView = (TextView) grid.findViewById(R.id.txt_grid);
textView.setText(cal[position]);
int x,y=0;
Linearlayout laycal =(Linearlayout)findViewById(R.id.laycal);
laycal.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case(ACTION_DOWN);
x = event.getX();
y = event.getY();
break;
case(ACTION_MOVE);
x = event.getX();
y = event.getY();
break;
case(ACTION_UP);
x = event.getX();
y = event.getY();
break;
}
return true;
}});
} else {
grid = (View) convertView;
}
return grid;
}