[Java for Android App Development] Floland:
Hello,

ive some trouble.

I want that when i press IN the rect that some new rect appear but it look like the app do this random because sometimes when i press on the sreen i will get back empty variables or the wrong.

thats GamePaint.java

package com.floland.quaders;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;

public class GamePaint extends Activity {

Game drawView;
float x;
float y;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawView = new Game(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
@Override
public boolean onTouchEvent(MotionEvent event) {

if(event.getAction() == MotionEvent.ACTION_DOWN){
x = event.getX();
y = event.getY();
Toast.makeText(GamePaint.this, " Y= " +y+ " X= " +x, Toast.LENGTH_LONG).show();
}
if (event.getAction() == MotionEvent.ACTION_UP) {

if((drawView.t <= y)&&(drawView.b >= y)&&(drawView.r <= x)&&(drawView.l >= x)) {
drawView = new Game(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
Toast.makeText(GamePaint.this, "Richtig :)", Toast.LENGTH_SHORT).show();
Toast.makeText(GamePaint.this, "T= " + drawView.t + " B= " + drawView.b + " R= " + drawView.r + " L= " + drawView.l, Toast.LENGTH_LONG).show();
}
if((drawView.t >= y)&&(drawView.b <= y)&&(drawView.r >= x)&&(drawView.l <= x)) {
drawView = new Game(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
Toast.makeText(GamePaint.this, "Richtig :)", Toast.LENGTH_SHORT).show();
Toast.makeText(GamePaint.this, "T= " + drawView.t + " B= " + drawView.b + " R= " + drawView.r + " L= " + drawView.l, Toast.LENGTH_LONG).show();
}
if((drawView.t <= y)&&(drawView.b >= y)&&(drawView.r >= x)&&(drawView.l <= x)) {
drawView = new Game(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
Toast.makeText(GamePaint.this, "Richtig :)", Toast.LENGTH_SHORT).show();
Toast.makeText(GamePaint.this, "T= " + drawView.t + " B= " + drawView.b + " R= " + drawView.r + " L= " + drawView.l, Toast.LENGTH_LONG).show();
}
if((drawView.t >= y)&&(drawView.b <= y)&&(drawView.r <= x)&&(drawView.l >= x)) {
drawView = new Game(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
Toast.makeText(GamePaint.this, "Richtig :)", Toast.LENGTH_SHORT).show();
Toast.makeText(GamePaint.this, "T= " + drawView.t + " B= " + drawView.b + " R= " + drawView.r + " L= " + drawView.l, Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(GamePaint.this, "Fehler", Toast.LENGTH_SHORT).show();
Toast.makeText(GamePaint.this, "T= " + drawView.t + " B= " + drawView.b + " R= " + drawView.r + " L= " + drawView.l, Toast.LENGTH_LONG).show();
}
}
return super.onTouchEvent(event);
}
}

thats Game.java

package com.floland.quaders;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.util.Random;

public class Game extends View {

Paint paint = new Paint();
Random rand = new Random();

int t;
int b;
int r;
int l;

public Game(Context context) {
super(context);
}

@Override
public void onDraw(Canvas canvas) {

int t = rand.nextInt(getBottom());
int b = rand.nextInt(getRight());
int r = rand.nextInt(getBottom());
int l = rand.nextInt(getRight());

if (t - b <= 10){
b = b + 10;
}
if (b - t <= 10){
t = t + 10;
}
if (l - r <= 10){
r = r + 10;
}
if (r - l <= 10){
l = l + 10;
}

paint.setColor(Color.BLACK);
paint.setStrokeWidth(0);
canvas.drawRect(l, t, r, b, paint);
//Left Top Right Bottom

Toast.makeText(getContext(), "T= " + t + " B= " + b + " R= " + r + " L= " + l+ " Bott= " + getBottom() + " Rigt= " + getRight() ,Toast.LENGTH_LONG).show();
}
}

I hope you can help me cause im a newbie :)

thanks

Floland