android - StartActivityfor result in customview -
i want invoke startactivity result when singletap on view detected.
for singletap on view, wrote follwing condition in ontouch method of view
@override public boolean ontouchevent(motionevent ev) { if (!msupportszoom && !msupportspan) return false; mscaledetector.ontouchevent(ev); final int action = ev.getaction(); switch (action & motionevent.action_mask) { case motionevent.action_down: { final float x = ev.getx(); final float y = ev.gety(); mlasttouchx = x; mlasttouchy = y; mactivepointerid = ev.getpointerid(0); break; } case motionevent.action_move: { final int pointerindex = ev.findpointerindex(mactivepointerid); final float x = ev.getx(pointerindex); final float y = ev.gety(pointerindex); if (msupportspan && !mscaledetector.isinprogress()) { final float dx = x - mlasttouchx; final float dy = y - mlasttouchy; mposx += dx; mposy += dy; //mfocusx = mposx; //mfocusy = mposy; invalidate(); } mlasttouchx = x; mlasttouchy = y; break; } case motionevent.action_up: { final float x = ev.getx(); final float y = ev.gety(); touchupx=x; touchupy=y; if(mlasttouchx == touchupx && mlasttouchy == touchupy){ //this condition detect single tap on view pinchzoompanactivity2.tapped(null, 100); //method startactivityfor result in main activity } mactivepointerid = invalid_pointer_id; break; } case motionevent.action_cancel: { mactivepointerid = invalid_pointer_id; break; } case motionevent.action_pointer_up: { final int pointerindex = (ev.getaction() & motionevent.action_pointer_index_mask) >> motionevent.action_pointer_index_shift; final int pointerid = ev.getpointerid(pointerindex); if (pointerid == mactivepointerid) { final int newpointerindex = pointerindex == 0 ? 1 : 0; mlasttouchx = ev.getx(newpointerindex); mlasttouchy = ev.gety(newpointerindex); mactivepointerid = ev.getpointerid(newpointerindex); } break; } } return true; } and tapped method in mainactivity follows
static void tapped(activity activity, int requestcode){ activity.startactivityforresult(new intent(intent.action_pick, android.provider.mediastore.images.media.internal_content_uri), 1); } but not work forecloses error null pointer exception.
please suggest wrong code.
pinchzoompanactivity2.tapped(null, 100); you're passing in null activity. tapped function tries call startactivityforresult on , fails because null.
Comments
Post a Comment