Search Results

Search found 71 results on 3 pages for 'ontouchevent'.

Page 1/3 | 1 2 3  | Next Page >

  • OnTouchEvent in a MapItemizedOverlay

    - by Danilo
    Hi, newbie here ... I have a MapView with a MapItemizedOverlay, like this : Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker); itemizedOverlay = new MapItemizedOverlay(drawable); OverlayItem overlayitem = new OverlayItem(p, "", ""); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); I want to know when the user touches the AndroiMarker, so I can show some info about that specific place. How do I do that ? Tks in advance!

    Read the article

  • Android - How to circular zoom/magnify part of image?

    - by IZI_Shadow_IZI
    I am trying to allow the user to touch the image and then basically a cirular magnifier will show that will allow the user to better select a certain area on the image. When the user releases the touch the magnified portion will dissapear. This is used on several photo editing apps and I am trying to implement my own version of it. The code I have below does magnify a circular portion of the imageview but does not delete or clear the zoom once I release my finger. I currently set a bitmap to a canvas using canvas = new Canvas(bitMap); and then set the imageview using takenPhoto.setImageBitmap(bitMap); I am not sure if I am going about it the right way. The onTouch code is below: zoomPos = new PointF(0,0); takenPhoto.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: zoomPos.x = event.getX(); zoomPos.y = event.getY(); matrix.reset(); matrix.postScale(2f, 2f, zoomPos.x, zoomPos.y); shader.setLocalMatrix(matrix); canvas.drawCircle(zoomPos.x, zoomPos.y, 20, shaderPaint); takenPhoto.invalidate(); break; case MotionEvent.ACTION_MOVE: zoomPos.x = event.getX(); zoomPos.y = event.getY(); matrix.reset(); matrix.postScale(2f, 2f, zoomPos.x, zoomPos.y); canvas.drawCircle(zoomPos.x, zoomPos.y, 20, shaderPaint); takenPhoto.invalidate(); break; case MotionEvent.ACTION_UP: //clear zoom here? break; case MotionEvent.ACTION_CANCEL: break; default: break; } return true; } });

    Read the article

  • Android: custom view onClickEvent with X & Y locations

    - by Martyn
    Hi, I've got a custom view and I want to get the X and Y coordinates of a user click. I've found that I can only get the coordinates from the onTouchEvent and an onClickEvent won't fire if I have an onTouchEvent. Unfortunately the onTouchEventfires when the user drags the screen as well as clicking. I've tried to differentiate between the two, but I still get the code firing when I'm dragging: public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN) { //fires on drag and click I've had a look at this but as I mentioned above I don't think the solution there will work as I can't get the onClick and the onTouch events working at the same time. Maybe I'm doing something wrong in this respect, is there a normal way of dealing with capturing user input on custom events? Should I be able to use the onClick and onTouch events at the same time? Thanks, Martyn

    Read the article

  • code for TouchPad works, but not for DPAD ...please help me to fix this..

    - by Chandan
    package org.coe.twoD; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; //import android.graphics.Path; import android.graphics.Rect; //import android.graphics.RectF; import android.os.Bundle; //import android.util.Log; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; public class TwoD extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View draw2d = findViewById(R.id.draw_button); draw2d.setOnClickListener(this); } public void onClick(View v) { if (R.id.draw_button == v.getId()) { setContentView(new draw2D(this)); } } public class draw2D extends View { private static final String TAG = "Sudoku"; private float width; // width of one tile private float height; // height of one tile private int selX; // X index of selection private int selY; // Y index of selection private final Rect selRect = new Rect(); public draw2D(Context context) { super(context); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { width = w / 9f; height = h / 9f; getRect(selX, selY, selRect); Log.d(TAG, "onSizeChanged: width " + width + ", height " + height); super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { // Draw the background... Paint background = new Paint(); background.setColor(getResources().getColor(R.color.background)); canvas.drawRect(0, 0, getWidth(), getHeight(), background); // Draw the board... // Define colors for the grid lines Paint dark = new Paint(); dark.setColor(getResources().getColor(R.color.dark)); Paint hilite = new Paint(); hilite.setColor(getResources().getColor(R.color.hilite)); Paint light = new Paint(); light.setColor(getResources().getColor(R.color.light)); // Draw the minor grid lines for (int i = 0; i < 9; i++) { canvas.drawLine(0, i * height, getWidth(), i * height, light); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, hilite); canvas.drawLine(i * width, 0, i * width, getHeight(), light); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), hilite); } // Draw the major grid lines for (int i = 0; i < 9; i++) { if (i % 3 != 0) continue; canvas.drawLine(0, i * height, getWidth(), i * height, dark); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, hilite); canvas.drawLine(i * width, 0, i * width, getHeight(), dark); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), hilite); } /* * dark.setColor(Color.MAGENTA); Path circle= new Path(); * circle.addCircle(150, 150, 100, Path.Direction.CW); * canvas.drawPath(circle, dark); * * * Path rect=new Path(); * * RectF rectf= new RectF(150,200,250,300); rect.addRect(rectf, * Path.Direction.CW); canvas.drawPath(rect, dark); * * * canvas.drawRect(0, 0,250, 250, dark); * * * canvas.drawText("Hello", 200,200, dark); */ Paint selected = new Paint(); selected.setColor(Color.GREEN); canvas.drawRect(selRect, selected); } /* * public boolean onTouchEvent(MotionEvent event){ * if(event.getAction()!=MotionEvent.ACTION_DOWN) return * super.onTouchEvent(event); * select((int)(event.getX()/width),(int)(event.getY()/height)); * * * return true; } */ private void select(int x, int y) { invalidate(selRect); selX = Math.min(Math.max(x, 0), 8); selY = Math.min(Math.max(y, 0), 8); getRect(selX, selY, selRect); invalidate(selRect); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return super.onKeyUp(keyCode, event); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() != MotionEvent.ACTION_DOWN) return super.onTouchEvent(event); select((int) (event.getX() / width), (int) (event.getY() / height)); // game.showKeypadOrError(selX, selY); Log.d(TAG, "onTouchEvent: x " + selX + ", y " + selY); return true; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.d(TAG, "onKeyDown: keycode=" + keyCode + ", event=" + event); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: select(selX, selY - 1); break; case KeyEvent.KEYCODE_DPAD_DOWN: select(selX, selY + 1); break; case KeyEvent.KEYCODE_DPAD_LEFT: select(selX - 1, selY); break; case KeyEvent.KEYCODE_DPAD_RIGHT: select(selX + 1, selY); break; default: return super.onKeyDown(keyCode, event); } return true; } private void getRect(int x, int y, Rect rect) { rect.set((int) (x * width), (int) (y * height), (int) (x * width + width), (int) (y * height + height)); } } }

    Read the article

  • Android: ScrollView in flipper

    - by Manu
    I have a flipper: <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/ParentLayout" xmlns:android="http://schemas.android.com/apk/res/android" style="@style/MainLayout" > <LinearLayout android:id="@+id/FlipperLayout" style="@style/FlipperLayout"> <ViewFlipper android:id="@+id/viewflipper" style="@style/ViewFlipper"> <!--adding views to ViewFlipper--> <include layout="@layout/home1" android:layout_gravity="center_horizontal" /> <include layout="@layout/home2" android:layout_gravity="center_horizontal" /> </ViewFlipper> </LinearLayout> </LinearLayout> The first layout,home1, consists of a scroll view. What should I do to distinguish between the flipping gesture and the scrolling? Presently: if I remove the scroll view, I can swipe across if I add the scroll view, I can only scroll. I saw a suggestion that I should override onInterceptTouchEvent(MotionEvent), but I do not know how to do this. My code, at this moment, looks like this: public class HomeActivity extends Activity { -- declares @Override public void onCreate(Bundle savedInstanceState) { -- declares & preliminary actions LinearLayout layout = (LinearLayout) findViewById(R.id.ParentLayout); layout.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; }}); @Override public boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); return true; } class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/ } } } Can anybody please guide me in the right direction? Thank you.

    Read the article

  • Getting coordinates when clicking anywhere on a MapView

    - by DixieFlatline
    I just cant get this working. I tried using the code below with onTouchEventand and it doesn't work. If i return true at the end of the method, i get the toast with the coordinates but can't move a map, and if i return false, i can move a map but cant display a toast after the user clicks on a map. If i get it right, the other onTap method is used only for clicking on a overlays. Has anybody figured this thiing out? public boolean onTouchEvent(MotionEvent arg0, MapView arg1) { //super.onTouchEvent(arg0); int akcija = arg0.getAction(); if(akcija == MotionEvent.ACTION_UP){ if(!premik) { Projection proj = mapView.getProjection(); GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY()); String sirina=Double.toString(loc.getLongitudeE6()/1000000); String dolzina=Double.toString(loc.getLatitudeE6()/1000000); Toast toast = Toast.makeText(getApplicationContext(), "Širina: "+sirina+" Dolzina: "+dolzina, Toast.LENGTH_LONG); toast.show(); } } else if (akcija == MotionEvent.ACTION_DOWN){ premik= false; } else if (akcija== MotionEvent.ACTION_MOVE){ premik = true; } return false; //return super.onTouchEvent(arg0); }

    Read the article

  • openGL ES - change the render mode from RENDERMODE_WHEN_DIRTY to RENDERMODE_CONTINUOUSLY on touch

    - by Sid
    i want to change the rendermode from RENDERMODE_WHEN_DIRTY to RENDERMODE_CONTINUOUSLY when i touch the screen. WHAT i Need : Initially the object should be stationary. after touching the screen, it should move automatically. The motion of my object is a projectile motion ans it is working fine. what i get : Force close and a NULL pointer exception. My code : public class BallThrowGLSurfaceView extends GLSurfaceView{ MyRender _renderObj; Context context; GLSurfaceView glView; public BallThrowGLSurfaceView(Context context) { super(context); // TODO Auto-generated constructor stub _renderObj = new MyRender(context); this.setRenderer(_renderObj); this.setRenderMode(RENDERMODE_WHEN_DIRTY); this.requestFocus(); this.setFocusableInTouchMode(true); glView = new GLSurfaceView(context.getApplicationContext()); } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub if (event != null) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (_renderObj != null) { Log.i("renderObj", _renderObj + "lll"); // Ensure we call switchMode() on the OpenGL thread. // queueEvent() is a method of GLSurfaceView that will do this for us. queueEvent(new Runnable() { public void run() { glView.setRenderMode(RENDERMODE_CONTINUOUSLY); } }); return true; } } } return super.onTouchEvent(event); } } PS : i know that i am making some silly mistakes in this, but cannot figure out what it really is.

    Read the article

  • Why does my performance increase when touching the screen?

    - by Smills
    For some reason my FPS jumps up considerably when I move my mouse around on the screen (on the emulator) while holding the left mouse button. Normally my game is very laggy, but if I touch the screen (and as long as I am moving the mouse around while touching) it goes perfectly smooth. I have tried sleeping for 20ms in the onTouchEvent, but it doesn't appear to make any difference. Here is the code I use in my onTouchEvent: // events when touching the screen public boolean onTouchEvent(MotionEvent event) { int eventaction = event.getAction(); touchX=event.getX(); touchY=event.getY(); switch (eventaction) { case MotionEvent.ACTION_DOWN: { touch=true; } break; case MotionEvent.ACTION_MOVE: { } break; case MotionEvent.ACTION_UP: { touch=false; } break; } /*try { AscentThread.sleep(20); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return true; } In the logcat log, FPS is the current fps (average of the last 20 frames), touch is whether or not the screen is being touched (from onTouchEvent). What on earth is going on? Has anyone else had this odd behaviour before? Logcat log: 12-21 19:43:26.154: INFO/myActivity(786): FPS: 31.686569159606414 Touch: false 12-21 19:43:27.624: INFO/myActivity(786): FPS: 19.46310293212206 Touch: false 12-21 19:43:29.104: INFO/myActivity(786): FPS: 18.801202175690467 Touch: false 12-21 19:43:30.514: INFO/myActivity(786): FPS: 21.118295877408478 Touch: false 12-21 19:43:31.985: INFO/myActivity(786): FPS: 19.117397812958878 Touch: false 12-21 19:43:33.534: INFO/myActivity(786): FPS: 15.572571858239263 Touch: false 12-21 19:43:34.934: INFO/myActivity(786): FPS: 20.584119901503506 Touch: false 12-21 19:43:36.404: INFO/myActivity(786): FPS: 18.888025905454207 Touch: false 12-21 19:43:37.814: INFO/myActivity(786): FPS: 22.35722329083629 Touch: false 12-21 19:43:39.353: INFO/myActivity(786): FPS: 15.73604859775362 Touch: false 12-21 19:43:40.763: INFO/myActivity(786): FPS: 20.912449882754633 Touch: false 12-21 19:43:42.233: INFO/myActivity(786): FPS: 18.785278388997718 Touch: false 12-21 19:43:43.634: INFO/myActivity(786): FPS: 20.1357397209596 Touch: false 12-21 19:43:45.043: INFO/myActivity(786): FPS: 21.961138432007957 Touch: false 12-21 19:43:46.453: INFO/myActivity(786): FPS: 22.167196852834273 Touch: false 12-21 19:43:47.854: INFO/myActivity(786): FPS: 22.207318228024274 Touch: false 12-21 19:43:49.264: INFO/myActivity(786): FPS: 22.36980559230175 Touch: false 12-21 19:43:50.604: INFO/myActivity(786): FPS: 23.587638823252547 Touch: false 12-21 19:43:52.073: INFO/myActivity(786): FPS: 19.233902040593076 Touch: false 12-21 19:43:53.624: INFO/myActivity(786): FPS: 15.542190150440987 Touch: false 12-21 19:43:55.034: INFO/myActivity(786): FPS: 20.82290063974675 Touch: false 12-21 19:43:56.436: INFO/myActivity(786): FPS: 21.975282007207717 Touch: false 12-21 19:43:57.914: INFO/myActivity(786): FPS: 18.786927284103687 Touch: false 12-21 19:43:59.393: INFO/myActivity(786): FPS: 18.96879004217992 Touch: false 12-21 19:44:00.625: INFO/myActivity(786): FPS: 28.367566618064878 Touch: false 12-21 19:44:02.113: INFO/myActivity(786): FPS: 19.04441528684418 Touch: false 12-21 19:44:03.585: INFO/myActivity(786): FPS: 18.807837511809065 Touch: false 12-21 19:44:04.993: INFO/myActivity(786): FPS: 21.134330284993418 Touch: false 12-21 19:44:06.275: INFO/myActivity(786): FPS: 27.209688764079907 Touch: false 12-21 19:44:07.753: INFO/myActivity(786): FPS: 19.055894653261653 Touch: false 12-21 19:44:09.163: INFO/myActivity(786): FPS: 22.05422794901088 Touch: false 12-21 19:44:10.644: INFO/myActivity(786): FPS: 18.6956805300596 Touch: false 12-21 19:44:12.124: INFO/myActivity(786): FPS: 17.434180581311054 Touch: false 12-21 19:44:13.594: INFO/myActivity(786): FPS: 18.71932038510891 Touch: false 12-21 19:44:14.504: INFO/myActivity(786): FPS: 40.94571503868066 Touch: true 12-21 19:44:14.924: INFO/myActivity(786): FPS: 57.061200121138576 Touch: true 12-21 19:44:15.364: INFO/myActivity(786): FPS: 62.54377946377936 Touch: true 12-21 19:44:15.764: INFO/myActivity(786): FPS: 64.05005071818726 Touch: true 12-21 19:44:16.384: INFO/myActivity(786): FPS: 50.912951172948155 Touch: true 12-21 19:44:16.874: INFO/myActivity(786): FPS: 55.31242053078078 Touch: true 12-21 19:44:17.364: INFO/myActivity(786): FPS: 59.31625410615102 Touch: true 12-21 19:44:18.413: INFO/myActivity(786): FPS: 36.63504170925923 Touch: false 12-21 19:44:19.885: INFO/myActivity(786): FPS: 18.099130467755923 Touch: false 12-21 19:44:21.363: INFO/myActivity(786): FPS: 18.458978222946566 Touch: false 12-21 19:44:22.683: INFO/myActivity(786): FPS: 25.582179409330823 Touch: true 12-21 19:44:23.044: INFO/myActivity(786): FPS: 60.99865521942455 Touch: true 12-21 19:44:23.403: INFO/myActivity(786): FPS: 74.17873975470984 Touch: true 12-21 19:44:23.763: INFO/myActivity(786): FPS: 64.25663040460714 Touch: true 12-21 19:44:24.113: INFO/myActivity(786): FPS: 62.47483457826921 Touch: true 12-21 19:44:24.473: INFO/myActivity(786): FPS: 65.27969529547072 Touch: true 12-21 19:44:24.825: INFO/myActivity(786): FPS: 67.84743115273311 Touch: true 12-21 19:44:25.173: INFO/myActivity(786): FPS: 73.50854551357706 Touch: true 12-21 19:44:25.523: INFO/myActivity(786): FPS: 70.46432534585368 Touch: true 12-21 19:44:25.873: INFO/myActivity(786): FPS: 69.04076953445896 Touch: true

    Read the article

  • two views ontouchlistener same area how to?

    - by user553465
    I have a two ImageView. 1.ImageView zomeImageMoveable : should zome in,out and moveable. 2.ImageView zomeImageFixed : show zome this is guide line. i want this two views work same touch. { FrameLayout myFrmae = new FrameLayout(this.getContext()); myFrame.addView(zomeImageMoveable); myFrame.addView(zomeImageFixed); } Case 1. below two ImageView have each listener ,but works only one. Case 2. FrameLayout add OnTouchListener and forward. but it doesn't work myFrame.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { zomeImageMoveable.onTouchEvent(event); zomeImageFixed.onTouchEvent(event); return false; } }); how do i have to do? thanks for reading.

    Read the article

  • Android: Touch seriously slowing my application

    - by Jason Rogers
    Hi all, I've been raking my brains on this one for a while. when I'm running my application (opengl game) eveyrthing goes fine but when I touch the screen my application slows down quite seriously (not noticeable on powerful phones like the nexus one, but on the htc magic it gets quite annoying). I did a trace and found out that the touch events seem to be handled in a different thread and even if it doesn't take so much processing time I think androids ability to switch between threads is not so good... What is the best way to handle touch when speed is an issue ? Currently I'm using : in the GLSurfaceView @Override public boolean onTouchEvent(MotionEvent event) { GameHandler.onTouchEvent(event); return true; } Any ideas are welcome

    Read the article

  • OnClickListener - x,y location of event?

    - by Mark
    Hi, I have a custom view derived from View. I'd like to be notified when the view is clicked, and the x,y location of where the click happened. Same for long-clicks. Looks like to do this, I need to override onTouchEvent(). Is there no way to get the x,y location of the event from an OnClickListener instead though? If not, what's a good way of telling if a motion event is a 'real' click vs a long-click etc? The onTouchEvent generates many events in rapid succession etc. Thanks

    Read the article

  • Trouble with detecting gestures over ListView

    - by Andrew
    I have an Activity that contains a ViewFlipper. The ViewFlipper includes 2 layouts, both of which are essentially just ListViews. So the idea here is that I have two lists and to navigate from one to the other I would use a horizontal swipe. I have that working. However, what ever list item your finger is on when the swipe begins executing, that item will also be long-clicked. Here is the relevant code I have: public class MyActivity extends Activity implements OnItemClickListener, OnClickListener { private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_MAX_OFF_PATH = 250; private static final int SWIPE_THRESHOLD_VELOCITY = 200; private GestureDetector mGestureDetector; View.OnTouchListener mGestureListener; class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { if (mCurrentScreen != SCREEN_SECONDLIST) { mCurrentScreen = SCREEN_SECONDLIST; mFlipper.setInAnimation(inFromRightAnimation()); mFlipper.setOutAnimation(outToLeftAnimation()); mFlipper.showNext(); updateNavigationBar(); } } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { if (mCurrentScreen != SCREEN_FIRSTLIST) { mCurrentScreen = SCREEN_FIRSTLIST; mFlipper.setInAnimation(inFromLeftAnimation()); mFlipper.setOutAnimation(outToRightAnimation()); mFlipper.showPrevious(); updateNavigationBar(); } } } catch (Exception e) { // nothing } return true; } } @Override public boolean onTouchEvent(MotionEvent event) { if (mGestureDetector.onTouchEvent(event)) return true; else return false; } ViewFlipper mFlipper; private int mCurrentScreen = SCREEN_FIRSTLIST; private ListView mList1; private ListView mList2; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.layout_flipper); mFlipper = (ViewFlipper) findViewById(R.id.flipper); mGestureDetector = new GestureDetector(new MyGestureDetector()); mGestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (mGestureDetector.onTouchEvent(event)) { return true; } return false; } }; // set up List1 screen mList1List = (ListView)findViewById(R.id.list1); mList1List.setOnItemClickListener(this); mList1List.setOnTouchListener(mGestureListener); // set up List2 screen mList2List = (ListView)findViewById(R.id.list2); mList2List.setOnItemClickListener(this); mList2List.setOnTouchListener(mGestureListener); } … } If I change the "return true;" statement from the GestureDetector to "return false;", I do not get long-clicks. Unfortunately, I get regular clicks. Does anyone know how I can get around this?

    Read the article

  • Joystick example problem for android 2D

    - by iQue
    I've searched all over the web for an answer to this, and there are simular topics but nothing works for me, and I have no Idea why. I just want to move my sprite using a joystick, since I'm useless at math when it comes to angles etc I used an example, Ill post the code here: public float initx = 50; //og 425; public float inity = 300; //og 267; public Point _touchingPoint = new Point(50, 300); //og(425, 267); public Point _pointerPosition = new Point(100, 170); private Boolean _dragging = false; private MotionEvent lastEvent; @Override public boolean onTouchEvent(MotionEvent event) { if (event == null && lastEvent == null) { return _dragging; } else if (event == null && lastEvent != null) { event = lastEvent; } else { lastEvent = event; } // drag drop if (event.getAction() == MotionEvent.ACTION_DOWN) { _dragging = true; } else if (event.getAction() == MotionEvent.ACTION_UP) { _dragging = false; } if (_dragging) { // get the pos _touchingPoint.x = (int) event.getX(); _touchingPoint.y = (int) event.getY(); // bound to a box if (_touchingPoint.x < 25) { _touchingPoint.x = 25; //og 400 } if (_touchingPoint.x > 75) { _touchingPoint.x = 75; //og 450 } if (_touchingPoint.y < 275) { _touchingPoint.y = 275; //og 240 } if (_touchingPoint.y > 325) { _touchingPoint.y = 325; //og 290 } // get the angle double angle = Math.atan2(_touchingPoint.y - inity, _touchingPoint.x - initx) / (Math.PI / 180); // Move the beetle in proportion to how far // the joystick is dragged from its center _pointerPosition.y += Math.sin(angle * (Math.PI / 180)) * (_touchingPoint.x / 70); _pointerPosition.x += Math.cos(angle * (Math.PI / 180)) * (_touchingPoint.x / 70); // stop the sprite from goin thru if (_pointerPosition.x + happy.getWidth() >= getWidth()) { _pointerPosition.x = getWidth() - happy.getWidth(); } if (_pointerPosition.x < 0) { _pointerPosition.x = 0; } if (_pointerPosition.y + happy.getHeight() >= getHeight()) { _pointerPosition.y = getHeight() - happy.getHeight(); } if (_pointerPosition.y < 0) { _pointerPosition.y = 0; } } public void render(Canvas canvas) { canvas.drawColor(Color.BLUE); canvas.drawBitmap(joystick.get_joystickBg(), initx-45, inity-45, null); canvas.drawBitmap(happy, _pointerPosition.x, _pointerPosition.y, null); canvas.drawBitmap(joystick.get_joystick(), _touchingPoint.x - 26, _touchingPoint.y - 26, null); } public void update() { this.onTouchEvent(null); } og= original position. as you can see Im trying to move the joystick, but when I do it stops working correctly, I mean it still works like a joystick but the sprite dosnt move accordingly, if I for example push the joystick down, the sprite moves up, and if I push it up it moves left. can anyone PLEASE help me, I've been stuck here for sooo long and its really frustrating.

    Read the article

  • ArrayAdapter and ListView - ArrayIndexOutOfBoundsException

    - by synic
    I'm really hoping someone can help me out with this one. I've been stuck on it forever. Occasionally, when someone is using my app, it'll force close with this exception: java.lang.ArrayIndexOutOfBoundsException at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:3572) at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2487) at android.widget.AbsListView.onTouchEvent(AbsListView.java:2001) at android.widget.ListView.onTouchEvent(ListView.java:3234) at android.view.View.dispatchTouchEvent(View.java:3709) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116) at android.app.Activity.dispatchTouchEvent(Activity.java:2068) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116) at android.app.Activity.dispatchTouchEvent(Activity.java:2068) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679) at android.view.ViewRoot.handleMessage(ViewRoot.java:1697) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4568) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at dalvik.system.NativeStart.main(Native Method) However, I cannot figure out why. It's relatively rare, non-reproducable, and the stacktrace is completely unhelpful because it doesn't include any of my code. Is it a bug in Android itself?

    Read the article

  • Android: how to tell if a view is scrolling

    - by Dave
    in iPhone, this would be simple---each view has a scrollViewDidScroll method. I am trying to find the equivalent in Android. My code works, but it isn't giving me what I want. I need to execute code the entire duration that a view is scrolling. So, even though I use OnGestureListener's onScroll method, it only fires when the finger is on the screen (it's not really named correctly---it should be called "onSlide" or "onSwipe", focusing on the gesture rather than the UI animation). It does not continue to fire if the user flicks the view and it is still scrolling for a few moments after the user lifts his finger. is there a method that is called at every step of the scroll? public class Scroll extends Activity implements OnGestureListener { public WebView webview; public GestureDetector gestureScanner; public int currentYPosition; public int lastYPosition; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); webview = new WebView(this); setContentView(webview); webview.loadUrl("file:///android_asset/Scroll.html"); gestureScanner = new GestureDetector(this); currentYPosition = 0; lastYPosition = 0; } public boolean onTouchEvent(final MotionEvent me) { return gestureScanner.onTouchEvent(me); } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // I do stuff here. return true; }

    Read the article

  • Android, FragmentActivity and prevent Swipe

    - by FIG-GHD742
    I use android.support.v4.app.FragmentActivity for create a app with multi fragment/panels that can be access by drag/swipe between different part of the app. In one of my fragment I has a zoomable view and my problem is in case I is on the zoomable view I will prevent the use for drag/swipe to a other fragment. I has try to hack into android.support.v4.view.ViewPager for get the action from on Touch event but not work. I has try all of this case but not work: (All code is a a part of subclass to android.support.v4.view.ViewPager) Case 1: // Not working @Override protected void onPageScrolled(int position, float offset, int offsetPixels) { if (isPreventDrag()) { super.onPageScrolled(position, 1, 0); } else { super.onPageScrolled(position, offset, offsetPixels); } } Case 2: // Work but stop all event include the event to the target image view. @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: lastX = ev.getX(); // float lockScroll = false; return super.onInterceptTouchEvent(ev); case MotionEvent.ACTION_MOVE: this.lockScroll = this.isPreventDrag(); break; } if (lockScroll) { ev.setLocation(lastX, ev.getY()); return super.onInterceptTouchEvent(ev); } else { return super.onInterceptTouchEvent(ev); } } Case 3: // Work good, but by some unknown error I can drag the screen // some pixels before this stop the event. @Override public boolean onTouchEvent(MotionEvent ev) { if (this.isPreventDrag()) { return true; } else { return super.onTouchEvent(ev); } } I want a easy way to deactivate stop or deactivate if the use is allow to switch to a other Fragment. Here is a working code for me, I don't know what error I do before. // This work for me, @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (this.isPreventDrag()) { return false; } else { return super.onInterceptTouchEvent(ev); } }

    Read the article

  • Subclassing ViewPager Breaks Animation

    - by Ryan Thomas
    In my Android application I have an activity which uses a view pager to display 4+ pages (Fragments). I implemented buttons on each screen that move between pages by calling: pager.setCurrentItem(position, true); The view pager and fragments are all working as I desired. I then began looking for a solution to disable user swiping between pages so that the transition between pages in handled by the buttons only. The solution I found was mentioned in a few stackoverflow articles as well as This Blog that suggest subclassing the view pager to intercept touch events to disable swiping. I followed those examples by subclassing the view pager class as follows: public class ViewPager extends android.support.v4.view.ViewPager { private boolean enabled; public ViewPager(Context context, AttributeSet attrs) { super(context, attrs); this.enabled = true; } @Override public boolean onTouchEvent(MotionEvent event) { if (this.enabled) { return super.onTouchEvent(event); } return false; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (this.enabled) { return super.onInterceptTouchEvent(event); } return false; } public void setSwipingEnabled(boolean enabled) { this.enabled = enabled; } } Using the subclassed view pager and calling setSwipingEnabled(false) works as was desired. The user can no longer move between pages with swipe gestures and I can still move between pages via button clicks by calling setCurrentItem(int position, boolean smoothScroll). However using the subclass breaks the animation between pages. When I call setCurrentItem(position, true) with android.support.v4.view.ViewPager I get very clean scrolling animations between pages. When I make the same call using the subclass the screen has a very brief 'flash' and then automatically draws the new page. I would like to know how to fix the animation while retaining the ability to disable user swiping between pages. I greatly appreciate any help with this. Let me know if you need any additional information. So far I have tested using a Samsung device running 2.3.5 and an AVD emulator targeting Android 2.3.3.

    Read the article

  • Android onFling not responding

    - by Kevin Moore
    I am new to android first of all so think of any newbie mistakes first I am trying to add a fling function in my code. public class MainGamePanel extends SurfaceView implements SurfaceHolder.Callback, OnGestureListener { private MainThread thread; private Droid droid; private Droid droid2; private static final String TAG = gameView.class.getSimpleName(); private GestureDetector gestureScanner; public MainGamePanel(Context context){ super(context); getHolder().addCallback(this); droid = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.playerbox2), 270, 300); droid2 = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.playerbox2), 50, 300); thread = new MainThread(getHolder(), this); setFocusable(true); gestureScanner = new GestureDetector(this); } public boolean onTouchEvent(MotionEvent event){ return gestureScanner.onTouchEvent(event); } @Override protected void onDraw(Canvas canvas){ canvas.drawColor(Color.BLACK); droid.draw(canvas); droid2.draw(canvas); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { droid.setX(50); droid.setY(50); Log.d(TAG, "Coords: x=" + e1.getX() + ",y=" + e2.getY()); return true; } @Override public boolean onDown(MotionEvent e) { droid2.setX((int)e.getX()); droid2.setY((int)e.getY()); Log.d(TAG, "Coords: x=" + e.getX() + ",y=" + e.getY()); return false; } I got the gestureListener to work with: onDown, onLongPress, and onShowPress. But i can't get any response with onFling, onSingleTapUp, and onScroll. What mistake am I making? does it have to do with views? I don't know what code would be useful to see.... so any suggestions would be much appreciated. Thank You!

    Read the article

  • Saving an interface instance into a Bundle

    - by user22241
    All I've have an interface that allows me to switch between different scenes in my Android game. When the home key is pressed, I am saving all of my states (score, sprite positions etc) into a Bundle. When re-launching, I am restoring all my states and all is OK - however, I can't figure out how to save my 'Scene', thus when I return, it always starts at the default screen which is the 'Main Menu'. How would I go about saving my 'Scene' (into a Bundle)? Code import android.view.MotionEvent; public interface Scene{ void render(); void updateLogic(); boolean onTouchEvent(MotionEvent event); } I assume the interface is the relevant piece of code which is why I've posted that snippet. I set my scene like so: ('options' is an object of my Options class which extends MainMenu (Another custom class) which, in turn implements the interface 'Scene') SceneManager.getInstance().setCurrentScene(options); //Current scene is optionscreen

    Read the article

  • Android how to get opengl 3D coordinates in ontouch event

    - by Sandy
    I created a cube in opengl and it rotates in ontouch event. To to this I created a CustomSurfaceView as follows public class CustomSurfaceView extends GLSurfaceView { @Override public boolean onTouchEvent(MotionEvent e) { float x = e.getX() float y = e.getY(); } } Here x and y are screen coordinates. How can I get 3D coordinated from this? I have already looked gluProject and NeHe. But I dont know how to implement this in my project, it shows that there is no GLdouble,GLfloat class.

    Read the article

  • Android -- autoLink

    - by Ryan
    Is there any way to Linkify a specific TextView that is contained within a ListView? I tried using android:autoLink="all" but that didn't work. I was getting an out of context error. Important also to note: the ListView is my second view in the ViewFlipper. I have also tried: View mItemView = mAdapter.getView(2, null, null); TextView infoText = (TextView) mItemView.findViewById(R.id.rowText2); Linkify.addLinks(infoText, Linkify.ALL); Right after the adapter was bound to the ListView and the View was switched. No luck. Here is the stack trace: 06-03 21:19:25.180: ERROR/AndroidRuntime(1214): Uncaught handler: thread main exiting due to uncaught exception 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.app.ApplicationContext.startActivity(ApplicationContext.java:550) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.content.ContextWrapper.startActivity(ContextWrapper.java:248) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.text.style.URLSpan.onClick(URLSpan.java:62) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:216) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.widget.TextView.onTouchEvent(TextView.java:6560) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.View.dispatchTouchEvent(View.java:3709) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.os.Handler.dispatchMessage(Handler.java:99) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.os.Looper.loop(Looper.java:123) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at android.app.ActivityThread.main(ActivityThread.java:4363) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at java.lang.reflect.Method.invokeNative(Native Method) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at java.lang.reflect.Method.invoke(Method.java:521) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 06-03 21:19:25.219: ERROR/AndroidRuntime(1214): at dalvik.system.NativeStart.main(Native Method) Any Ideas? Thanks in advance!!!

    Read the article

  • Android Window Mananger leacked windwo progress dialog

    - by saravanan-palpandi
    05-14 16:53:52.273: ERROR/WindowManager(412): Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43db2e68 that was originally added here 05-14 16:53:52.273: ERROR/WindowManager(412): android.view.WindowLeaked: Activity com.sss.client.AddClient has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43db2e68 that was originally added here 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewRoot.(ViewRoot.java:227) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.Window$LocalWindowManager.addView(Window.java:424) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.app.Dialog.show(Dialog.java:239) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.app.ProgressDialog.show(ProgressDialog.java:107) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.app.ProgressDialog.show(ProgressDialog.java:90) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.app.ProgressDialog.show(ProgressDialog.java:85) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.sss.client.AddClient.searchValues(AddClient.java:236) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.sss.client.AddClient.clientFormAction(AddClient.java:264) 05-14 16:53:52.273: ERROR/WindowManager(412): at java.lang.reflect.Method.invokeNative(Native Method) 05-14 16:53:52.273: ERROR/WindowManager(412): at java.lang.reflect.Method.invoke(Method.java:521) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.View$1.onClick(View.java:2026) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.View.performClick(View.java:2364) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.View.onTouchEvent(View.java:4179) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.widget.TextView.onTouchEvent(TextView.java:6540) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.View.dispatchTouchEvent(View.java:3709) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.os.Handler.dispatchMessage(Handler.java:99) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.os.Looper.loop(Looper.java:123) 05-14 16:53:52.273: ERROR/WindowManager(412): at android.app.ActivityThread.main(ActivityThread.java:4363) 05-14 16:53:52.273: ERROR/WindowManager(412): at java.lang.reflect.Method.invokeNative(Native Method) 05-14 16:53:52.273: ERROR/WindowManager(412): at java.lang.reflect.Method.invoke(Method.java:521) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 05-14 16:53:52.273: ERROR/WindowManager(412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 05-14 16:53:52.273: ERROR/WindowManager(412): at dalvik.system.NativeStart.main(Native Method) when show the dialog box it show the error message please do reply me

    Read the article

  • Can't find method in the activity

    - by Synesso
    I'm starting with Scala + Android. I'm trying to wire a button action to a button without the activity implementing View.OnClickListener. The button click fails at runtime because the method cannot be found. The document I'm working through says that I need only declare a public void method taking a View on the action, and use that method name in the layout. What have I done wrong? MainActivity.scala package net.badgerhunt.hwa import android.app.Activity import android.os.Bundle import android.widget.Button import android.view.View import java.util.Date class MainActivity extends Activity { override def onCreate(savedInstanceState: Bundle) = { super.onCreate(savedInstanceState) setContentView(R.layout.main) } def calculate(button: View): Unit = println("calculating with %s ...".format(button)) } res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <Button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button" android:text="" android:onClick="calculate" android:layout_width="fill_parent" android:layout_height="fill_parent"/> the failure onclick D/AndroidRuntime( 362): Shutting down VM W/dalvikvm( 362): threadid=3: thread exiting with uncaught exception (group=0x4001b188) E/AndroidRuntime( 362): Uncaught handler: thread main exiting due to uncaught exception E/AndroidRuntime( 362): java.lang.IllegalStateException: Could not find a method calculate(View) in the activity E/AndroidRuntime( 362): at android.view.View$1.onClick(View.java:2020) E/AndroidRuntime( 362): at android.view.View.performClick(View.java:2364) E/AndroidRuntime( 362): at android.view.View.onTouchEvent(View.java:4179) E/AndroidRuntime( 362): at android.widget.TextView.onTouchEvent(TextView.java:6540) E/AndroidRuntime( 362): at android.view.View.dispatchTouchEvent(View.java:3709) E/AndroidRuntime( 362): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) E/AndroidRuntime( 362): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) E/AndroidRuntime( 362): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) E/AndroidRuntime( 362): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) E/AndroidRuntime( 362): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) E/AndroidRuntime( 362): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) E/AndroidRuntime( 362): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) E/AndroidRuntime( 362): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) E/AndroidRuntime( 362): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 362): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 362): at android.app.ActivityThread.main(ActivityThread.java:4363) E/AndroidRuntime( 362): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 362): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime( 362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) E/AndroidRuntime( 362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) E/AndroidRuntime( 362): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 362): Caused by: java.lang.NoSuchMethodException: calculate E/AndroidRuntime( 362): at java.lang.ClassCache.findMethodByName(ClassCache.java:308) E/AndroidRuntime( 362): at java.lang.Class.getMethod(Class.java:1014) E/AndroidRuntime( 362): at android.view.View$1.onClick(View.java:2017) E/AndroidRuntime( 362): ... 20 more

    Read the article

  • how to implement add item in spinner array adapter in android

    - by narasimha
    hi folks, i had a EditText , a button and a spinner . When click the button , the spinner will add a new item with name you entered in the EditText. But here is the question, my adapter.add() method seems doesn't work...here is my code: bt1 = (Button)this.findViewById(R.id.AddBtn); et = (EditText)this.findViewById(R.id.newSpinnerItemText); spinner = (Spinner)this.findViewById(R.id.dynamicSpinner); adapter = ArrayAdapter.createFromResource( this, R.array.simple_from_length, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String temp = et.getText().toString(); adapter.add(temp); // adapter.notifyDataSetChanged(); spinner.setAdapter(adapter); } }); error of this file: 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): java.lang.UnsupportedOperationException 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at java.util.AbstractList.add(AbstractList.java:410) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at java.util.AbstractList.add(AbstractList.java:432) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.widget.ArrayAdapter.add(ArrayAdapter.java:178) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at org.example.SpinnerKiran.SpinnerKiran$1.onClick(SpinnerKiran.java:56) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.View.performClick(View.java:2179) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.View.onTouchEvent(View.java:3828) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.widget.TextView.onTouchEvent(TextView.java:6291) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.View.dispatchTouchEvent(View.java:3368) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1707) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1197) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.app.Activity.dispatchTouchEvent(Activity.java:1993) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1691) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.view.ViewRoot.handleMessage(ViewRoot.java:1525) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.os.Handler.dispatchMessage(Handler.java:99) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.os.Looper.loop(Looper.java:123) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at android.app.ActivityThread.main(ActivityThread.java:3948) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at java.lang.reflect.Method.invokeNative(Native Method) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at java.lang.reflect.Method.invoke(Method.java:521) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 02-27 18:01:17.728: ERROR/AndroidRuntime(1982): at dalvik.system.NativeStart.main(Native Method)

    Read the article

1 2 3  | Next Page >