I want to fliding view use gallery,in my view have two edittext,but when i 
click the second edittext,The first edittext always get focus.
this is my xml
 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="1200dip"
        android:orientation="vertical" >
        <EditText
            android:id="@+id/autotext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:singleLine="true"
            android:textColor="#5B5B5B"
            android:textSize="15sp" />
         <EditText
                android:id="@+id/consumecalories"
                android:layout_width="180dp"
                android:layout_height="45dp"
                android:layout_marginLeft="10dp"
                android:inputType="numberDecimal"
                android:textColor="#5B5B5B"
                android:textSize="15sp"
                android:textStyle="bold" />
  </LinearLayout>
this is my Gallery,
public class MyGallery extends Gallery {

public MyGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initCustomGallery(context);
// TODO Auto-generated constructor stub
}

public MyGallery(Context context, AttributeSet attrs) {
super(context, attrs);
initCustomGallery(context);
// TODO Auto-generated constructor stub
}

public MyGallery(Context context) {
super(context);
initCustomGallery(context);
// TODO Auto-generated constructor stub
}@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
mTouchStartX = ev.getX();
mTouchStartY = ev.getY();
mScrollLock = SCROLL_LOCK_NONE;

/**
 * Deliver the down event to the Gallery to avoid jerky scrolling if
 * we decide to redirect the ScrollView events to ourself
 */
super.onTouchEvent(ev);
break;

case MotionEvent.ACTION_MOVE:
if (mScrollLock == SCROLL_LOCK_VERTICAL) {
// keep returning false to pass the events
// onto the ScrollView
return false;
}

final float touchDistanceX = (ev.getX() - mTouchStartX);
final float touchDistanceY = (ev.getY() - mTouchStartY);

if (Math.abs(touchDistanceY) > mDragBoundsInPx) {
mScrollLock = SCROLL_LOCK_VERTICAL;
return false;
}
if (Math.abs(touchDistanceX) > mDragBoundsInPx) {
mScrollLock = SCROLL_LOCK_HORIZONTAL; // gallery action
return true; // redirect MotionEvents to ourself
}
break;

case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
// if we're still intercepting at this stage, make sure the gallery
// also recieves the up/cancel event as we gave it the down event
// earlier
super.onTouchEvent(ev);
break;
}

return false;
}

 @Override
public boolean onDown(MotionEvent e) {
return false;
}

 @Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
if (getFocusedChild() != null) {
handled = getFocusedChild().dispatchKeyEvent(event);
}

if (!handled) {
handled = event.dispatch(this, null, null);
}
return handled;
}
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to