Hello,
I have a mess right now.., and I would like to start using the View
instead of coding in the main activity... what and how would I pass my
code in the main activity so that it works from the View I created?
This is the view i created and where i want to place the code of the
main activity
public class GameView extends View{
public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public GameView(Context context, AttributeSet attrs, int
defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public GameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
}
}
Here is my main Activity which is a mess.... each OnTouch changes the
an image from invisible to visible
package com.beatyourmemory1.game;
public class GameActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myviewlay);
final ImageView image1=
(ImageView)findViewById(R.id.ImageView03);
image1.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try {
Thread.sleep(200);
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
image1.setVisibility(View.INVISIBLE);
}
else
{
image1.setVisibility(View.VISIBLE);
}
//return super.onTouchEvent(event);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
});
final ImageView image2=
(ImageView)findViewById(R.id.ImageView02);
image2.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try {
Thread.sleep(200);
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
image2.setVisibility(View.INVISIBLE);
}
else
{
image2.setVisibility(View.VISIBLE);
}
//return super.onTouchEvent(event);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
});
final ImageView image3=
(ImageView)findViewById(R.id.ImageView01);
image3.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try {
Thread.sleep(200);
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
image3.setVisibility(View.INVISIBLE);
}
else
{
image3.setVisibility(View.VISIBLE);
}
//return super.onTouchEvent(event);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
});
final ImageView image4=
(ImageView)findViewById(R.id.ImageView04);
image4.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try {
Thread.sleep(200);
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
image4.setVisibility(View.INVISIBLE);
}
else
{
image4.setVisibility(View.VISIBLE);
}
//return super.onTouchEvent(event);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
});
}
}//class
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en