|
You last visited: Today at 12:42
Advertisement
Java(Android) clear deaktivieren
Discussion on Java(Android) clear deaktivieren within the Java forum part of the Coders Den category.
06/15/2014, 20:56
|
#1
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Java(Android) clear deaktivieren
Guten Abend mal wieder,
ich stoße mal wieder an ein Problem, ich habe eine App geschrieben in welcher ein roter Bildschirm mit einem kleinen gelben "Ball" auftaucht. Wenn ich irgendwo auf den Bildschirm drücke/tappe springt der "Ball" dort hin bzw. es wird die Position gewechselt und der Bildschirm neu geladen wodurch der "alte Ball" nicht mehr zu sehen ist, ich möchte jedoch , dass dieser noch zu sehen ist und ich sozusagen "malen" kann wie stelle ich es also nun ab das die "Bälle" wieder gelöscht werden?
|
|
|
06/16/2014, 22:35
|
#2
|
elite*gold: 31
Join Date: Jan 2014
Posts: 310
Received Thanks: 55
|
Du kannst doch einfach einen neuen Ball dort spawnen, wo du hintippst.
|
|
|
06/21/2014, 14:41
|
#3
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Jedoch wie? Dafür müsste ich in einem onTouch event auf die onDraw Methode zugreifen, dass geht allerdings nicht und wie kann ich automatisch eine neue RectF Variable erstellen?
MfG Joshi
|
|
|
06/21/2014, 18:10
|
#4
|
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
|
Mach einfach eine Liste in die bei jeder Berührung ein neues Element mit den Koordinaten hinzugefügt wird, dann gehst du diese Liste in der draw Methode durch.
|
|
|
06/21/2014, 18:56
|
#5
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Mit beispielsweise einem Array?
|
|
|
06/22/2014, 11:30
|
#6
|
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
|
Mach dir eine ArrayList von "Point" =
Code:
ArrayList<Point> liste = new ArrayList<Point>();
Über liste.add([POINT]); und liste.remove(XX); kannst du dann während der Laufzeit die Koordinaten mittels "Point" in die Liste speichern oder entfernen.
|
|
|
06/22/2014, 15:23
|
#7
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Ahhh vielen dank habe es mit nem Array ausprobiert und zwei sich steigenden Variablen und Wertzuweisung jedoch startet die App dann garnicht mehr ^^.
Was ist mit "Point" gemeint die X und Y Coordinate als Graph oder wie kann ich mir das vorstellen?
Bzw. wie ist es möglich zwei Koordinaten in einen Punkt zu "konvertieren"?
|
|
|
06/22/2014, 15:39
|
#8
|
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
|
Es gibt in Java eine Klasse die heißt "Point". Dort kannst du die X und Y Koordinaten ablegen.
Code:
Point punkt1 = new Point(50, 50);
int x = punkt1.x;
int y = punkt1.y;
|
|
|
06/22/2014, 15:49
|
#9
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Jetzt kommt aber das Problem dass ich zum zeichen RectF nutzen muss welches mit float Daten funktioniert und nicht mit Point O.o.
Dass das so kompliziert ist hätte ich nicht gedacht....
Code:
private float BallX;
private float BallY;
private RectF ballbounds;
.
.
.
ballbounds.set(BallX-ballradius, BallY-ballradius, BallX+ballradius, BallY+ballradius);
|
|
|
06/22/2014, 15:59
|
#10
|
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
|
Point hat 2 Variablen, einmal X und dann noch Y. Die kannst du einfach über deinPoint.x/y; abrufen, dass liefert dir dann einen Integer zurück... der Integer passt immer in eine float Variable.
Code:
private Point deinPunkt = new Point(deinXWert, deinYWert);
private float BallX = deinPunkt.x;
private float BallY = deinPunkt.y;
private RectF ballbounds;
.
.
.
ballbounds.set(BallX-ballradius, BallY-ballradius, BallX+ballradius, BallY+ballradius);
|
|
|
06/22/2014, 16:22
|
#11
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Es funktioniert nun garnichts mehr haha.....wärest du eventuell so freundlich und würdest dir den Code mal ansehen? =))
Code:
package com.terratroll.draw;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.Random;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.view.MotionEvent;
import android.view.View;
public class DrawView extends View {
private float ballradius = 65;
private RectF ballbounds;
private Paint paint;
private float BallX = ballradius + 180;
private float BallY = ballradius + 280;
private int xMin = 0; // This view's bounds
private int xMax;
private int yMin = 0;
private int yMax;
private int v = 0;
private ArrayList<Point> liste = new ArrayList<Point>();
private float tapX;
private float tapY;
private Point point;
public DrawView(Context context) {
super(context);
ballbounds = new RectF();
paint = new Paint();
paint.setColor(Color.YELLOW);
}
public void onDraw(Canvas canvas){
if(point.x != 0&&point.y != 0){
BallX = point.x;
BallY = point.y;}
ballbounds.set(BallX-ballradius, BallY-ballradius, BallX+ballradius, BallY+ballradius);
canvas.drawOval(ballbounds, paint);
try {
Thread.sleep(30);
} catch (InterruptedException e) { }
invalidate(); // Force a re-draw
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getActionMasked()){
case MotionEvent.ACTION_DOWN:
tapX = event.getX();
tapY = event.getY();
point = new Point((int)tapX,(int)tapY);
liste.add(1,point);
}
return true;
}
@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
// Set the movement bounds for the ball
xMax = w-1;
yMax = h-1;
}
}
|
|
|
06/22/2014, 16:35
|
#12
|
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
|
Was genau geht denn nicht?
So sollte es funktionieren:
Code:
public class DrawView extends View {
private float ballradius = 65;
private RectF ballbounds;
private Paint paint;
private float BallX = ballradius + 180;
private float BallY = ballradius + 280;
private int xMin = 0; // This view's bounds
private int xMax;
private int yMin = 0;
private int yMax;
private int v = 0;
private ArrayList<Point> liste = new ArrayList<Point>();
private float tapX;
private float tapY;
public DrawView(Context context) {
super(context);
ballbounds = new RectF();
paint = new Paint();
paint.setColor(Color.YELLOW);
}
public void onDraw(Canvas canvas){
for(Point p : liste){ //Die Liste mit einer For-Each Schleife durchlaufen
if(p.x != 0 && p.y != 0){
BallX = p.x;
BallY = p.y;}
ballbounds.set(BallX-ballradius, BallY-ballradius, BallX+ballradius, BallY+ballradius);
canvas.drawOval(ballbounds, paint);
}
try {
Thread.sleep(30);
} catch (InterruptedException e) { }
invalidate(); // Force a re-draw
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getActionMasked()){
case MotionEvent.ACTION_DOWN:
tapX = event.getX();
tapY = event.getY();
liste.add(new Point( (int)tapX, (int)tapY) ); //Der Liste einen neuen Punkt hinzufügen
}
return true;
}
@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
// Set the movement bounds for the ball
xMax = w-1;
yMax = h-1;
}
}
|
|
|
06/22/2014, 16:40
|
#13
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Die App schließt sich direkt nachdem Starten und LogCat spuckt einen NullExceptionError aus ^^
*_* VIELEN DANK!!!! ES FUNKTIONIERT TATSÄCHLICH!!!!
Wollte nun alles in die Main packen damit ich auch den GestureDetector verwenden kann jedoch will das nicht so ganz.
Code:
package com.terratroll.draw;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v4.view.MotionEventCompat;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
//Implement this interface to be notified when a gesture occurs
public class MainActivity extends Activity implements OnGestureListener
{
//creates a Gesture Detector
private GestureDetector gd;
private float ballradius = 65;
private RectF ballbounds;
private Paint paint;
private float BallX = ballradius + 180;
private float BallY = ballradius + 280;
private ArrayList<Point> liste = new ArrayList<Point>();
private float tapX;
private float tapY;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View drawView = new View(this);
setContentView(drawView);
drawView.setBackgroundColor(Color.RED);
//initialize the Gesture Detector
gd = new GestureDetector(this);
//set the on Double tap listener
gd.setOnDoubleTapListener(new OnDoubleTapListener()
{
@Override
public boolean onDoubleTap(MotionEvent e)
{
//set text color to green
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e)
{
//if the second tap hadn't been released and it's being moved
if(e.getAction() == MotionEvent.ACTION_MOVE)
{
}
else if(e.getAction() == MotionEvent.ACTION_UP)//user released the screen
{
}
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e)
{
return false;
}
});
}
public class drawView extends View{
public drawView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
ballbounds = new RectF();
paint = new Paint();
paint.setColor(Color.YELLOW);
//for(Point p : liste){ //Die Liste mit einer For-Each Schleife durchlaufen
// if(p.x != 0 && p.y != 0){
// BallX = p.x;
// BallY = p.y;}
ballbounds.set(BallX-ballradius, BallY-ballradius, BallX+ballradius, BallY+ballradius);
canvas.drawOval(ballbounds, paint);
//}
try {
Thread.sleep(30);
} catch (InterruptedException e) { }
invalidate(); // Force a re-draw
}
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch(event.getActionMasked()){
case MotionEvent.ACTION_MOVE:
tapX = event.getX();
tapY = event.getY();
liste.add(new Point( (int)tapX, (int)tapY) ); //Der Liste einen neuen Punkt hinzufügen
}
return true;
}
@Override
public boolean onDown(MotionEvent e)
{
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
return false;
}
@Override
public void onLongPress(MotionEvent e)
{
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
return false;
}
@Override
public void onShowPress(MotionEvent e)
{
}
@Override
public boolean onSingleTapUp(MotionEvent e)
{
return false;
}
}
|
|
|
06/23/2014, 08:48
|
#14
|
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
|
Du hast die for-each auskommentiert, so haben BallX und BallY immer den selben am Anfang zugeteilten Wert.
Code:
package com.terratroll.draw;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v4.view.MotionEventCompat;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
//Implement this interface to be notified when a gesture occurs
public class MainActivity extends Activity implements OnGestureListener
{
//creates a Gesture Detector
private GestureDetector gd;
private float ballradius = 65;
private RectF ballbounds;
private Paint paint;
private float BallX = ballradius + 180;
private float BallY = ballradius + 280;
private ArrayList<Point> liste = new ArrayList<Point>();
private float tapX;
private float tapY;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View drawView = new View(this);
setContentView(drawView);
drawView.setBackgroundColor(Color.RED);
//initialize the Gesture Detector
gd = new GestureDetector(this);
//set the on Double tap listener
gd.setOnDoubleTapListener(new OnDoubleTapListener()
{
@Override
public boolean onDoubleTap(MotionEvent e)
{
//set text color to green
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e)
{
//if the second tap hadn't been released and it's being moved
if(e.getAction() == MotionEvent.ACTION_MOVE)
{
}
else if(e.getAction() == MotionEvent.ACTION_UP)//user released the screen
{
}
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e)
{
return false;
}
});
}
public class drawView extends View{
public drawView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
ballbounds = new RectF();
paint = new Paint();
paint.setColor(Color.YELLOW);
for(Point p : liste){ //Die Liste mit einer For-Each Schleife durchlaufen
if(p.x != 0 && p.y != 0){
BallX = p.x;
BallY = p.y;}
ballbounds.set(BallX-ballradius, BallY-ballradius, BallX+ballradius, BallY+ballradius);
canvas.drawOval(ballbounds, paint);
}
try {
Thread.sleep(30);
} catch (InterruptedException e) { }
invalidate(); // Force a re-draw
}
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch(event.getActionMasked()){
case MotionEvent.ACTION_MOVE:
tapX = event.getX();
tapY = event.getY();
liste.add(new Point( (int)tapX, (int)tapY) ); //Der Liste einen neuen Punkt hinzufügen
}
return true;
}
@Override
public boolean onDown(MotionEvent e)
{
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
return false;
}
@Override
public void onLongPress(MotionEvent e)
{
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
return false;
}
@Override
public void onShowPress(MotionEvent e)
{
}
@Override
public boolean onSingleTapUp(MotionEvent e)
{
return false;
}
}
Nichts gegen dich, aber du solltest dir den Code selbst schreiben und nicht Codefetzen aus Foren benutzen.
|
|
|
06/23/2014, 18:56
|
#15
|
elite*gold: 260
Join Date: Sep 2012
Posts: 206
Received Thanks: 13
|
Ja damit hast du warscheinlich Recht :/ ich brauchen wohl einfach mehr Zeit zum lernen ^^ wie lange machst du das schon?
|
|
|
 |
Similar Threads
|
[Trading] [S] Lehrer Java für Android app
05/29/2014 - Trading - 1 Replies
Topic
|
Suche Java (Android) Programmierer
09/25/2013 - Coders Trading - 7 Replies
Hey,
Ich suche jemanden, der fit in Java bzgl. Android ist. Das ganze soll keine Aufgabe bzw. Auftrag sein, sondern ein Projekt, was zu zweit realisiert wird. Dieses Projekt stellt eine Art Service für Programmierer und Softwarevertreiber jeder Art dar.
Es wird jemand mit Erfahrung gesucht und nicht jemand, der denkt evtl. könnte er es in 3 Monaten schaffen.
Einige Beispiele, die ihr können solltet: Notifications, Oberflächengestaltung (ihr sollt kein Grafiker sein, aber das ganze...
|
[Android 4.04] Java Problem
10/09/2012 - Smartphones - 1 Replies
Hi ich kriege immer folgende Meldung, wenn ich ne App starte die Java benötigt...
oder
Wie behebe ich das Problem?
|
Java ( Android App )
03/05/2012 - General Coding - 6 Replies
Hey Leute (;
Mir ist heute so eine super idee geschossen und diese wollte ich sofort in ein kleines App für Android umetzen ^^
Mitlerweile bin ich schon ne Stunde am Googlen dran find aber einfach nicht wie es geht.
Also..
Hatt jemand eine idee wie ich das Microphon vom Handy ansprechen könnte, dass es die ganze Zeit zu hört und dann das "gehörte" mit einer Datei die auf dem Handy liegt vergleicht?
Also so im Shazam Prinzip Anhören --> Vergleichen
|
Wie bei Android 1.6 G2 + G3 Deaktivieren?
08/23/2010 - Smartphones - 5 Replies
hey
ich habe ein problem derzeit.
ich habe ein neues handy mit Android 1.6
das problem ist, es geht immer automatisch ins internet.
Das kostet mir dann pro tag 99 cent -.-" (prepaid)
Ich will eigentlich nur Wlan benutzen!!!
aber ich schafe es nicht, es zu deaktivieren.
Vielleicht habt ihr tipps für mich (:
würde mich freuen über jede antwort!!!
|
All times are GMT +1. The time now is 12:43.
|
|