I'm using Android Studio to create a small drag and drop application. I have followed all the rules I know and the code doesn't seem to have any errors, however when I run it on my device it simple crashes. Anyone know where its wrong?
The code is fine until initialise(); is called in public void blue(View v)
so I'm suspecting the error is there
public class MainActivity extends Activity {
private ImageView blueball;
private ImageView blueballdrag;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void colourGen(View view){
int i =1;
if (i==i){
blue(view);
}
}
public void brown(View v){
setContentView(R.layout.activity_brown);
}
public void yellow (View v){
setContentView(R.layout.activity_yellow);
}
public void green (View v){
setContentView(R.layout.activity_green);
}
public void blue (View v){
setContentView(R.layout.activity_blue);
initialise();
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void initialise() {
final ImageView imageView = (ImageView) blueballdrag.findViewById(R.id.imageView4);
imageView.setOnDragListener(new View.OnDragListener() {
public boolean onDrag(View v, DragEvent dragEvent) {
switch (dragEvent.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
v.setBackgroundColor(Color.RED);
case DragEvent.ACTION_DRAG_ENTERED:
v.setBackgroundColor(Color.BLACK);
case DragEvent.ACTION_DRAG_ENDED:
v.setBackgroundColor(Color.GREEN);
case DragEvent.ACTION_DROP:
v.setBackgroundColor(Color.WHITE);
}
return false;
}
});
blueball = (ImageView) findViewById(R.id.imageView6);
blueball.setOnLongClickListener(new OnLongClickListener(){
#Override
public boolean onLongClick(View v) {
View.DragShadowBuilder myShadow = new MyDragShadowBuilder(blueball);
v.startDrag(null, myShadow, null, 0);
return false;
}
});
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static class MyDragShadowBuilder extends View.DragShadowBuilder {
private static Drawable shadow;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public MyDragShadowBuilder(View v) {
super(v);
shadow = new ColorDrawable(Color.RED);
}
public void onProvideShadowMetrics(Point size, Point touch){
int width, height;
width = getView().getWidth() * 2;
height = getView().getHeight() * 2;
shadow.setBounds(0, 0, width, height);
size.set(width, height);
touch.set(width*2, height*2);
}
public void onDrawShadow(Canvas canvas){
shadow.draw(canvas);
}
}
}
The problem is the line
final ImageView imageView = (ImageView) blueballdrag.findViewById(R.id.imageView4);
This line tells the Object blueballdrag to find a child view called imageView4. I'm guessing that your ImageViews don't have children. You want the findViewById() method of your Activity, not your View.
Changing the line to the following should solve your problem.
final ImageView imageView = (ImageView) findViewById(R.id.imageView4);
Related
I want to create my own emoji keyboard in android. User should be able to select this keyboard as an input method for his android phone.
I tried creating it and I am able to use it in my app but I have no idea how to make this as an input method so this keyboard will be available to all other apps in my phone.
I read somewhere that I have to create a service for that so that it bind with input service.Other than that I am not able to understand rest of the thing.
Here is what I did. Though it is different from what I want to do but is start and don't know how to proceed further.
public class MainActivity extends FragmentActivity implements EmoticonsGridAdapter.KeyClickListener {
private static final int NO_OF_EMOTICONS = 100;
private ListView chatList;
private View popUpView;
private ArrayList<Spanned> chats;
private ChatListAdapter mAdapter;
private LinearLayout emoticonsCover;
private PopupWindow popupWindow;
private int keyboardHeight;
private EditText content;
private LinearLayout parentLayout;
private boolean isKeyBoardVisible;
private Bitmap[] emoticons;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chatList = (ListView) findViewById(R.id.chat_list);
parentLayout = (LinearLayout) findViewById(R.id.list_parent);
emoticonsCover = (LinearLayout) findViewById(R.id.footer_for_emoticons);
popUpView = getLayoutInflater().inflate(R.layout.emoticons_popup, null);
// Setting adapter for chat list
chats = new ArrayList<Spanned>();
mAdapter = new ChatListAdapter(getApplicationContext(), chats);
chatList.setAdapter(mAdapter);
chatList.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (popupWindow.isShowing())
popupWindow.dismiss();
return false;
}
});
// Defining default height of keyboard which is equal to 230 dip
final float popUpheight = getResources().getDimension(
R.dimen.keyboard_height);
changeKeyboardHeight((int) popUpheight);
// Showing and Dismissing pop up on clicking emoticons button
ImageView emoticonsButton = (ImageView) findViewById(R.id.emoticons_button);
emoticonsButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!popupWindow.isShowing()) {
popupWindow.setHeight((int) (keyboardHeight));
if (isKeyBoardVisible) {
emoticonsCover.setVisibility(LinearLayout.GONE);
} else {
emoticonsCover.setVisibility(LinearLayout.VISIBLE);
}
popupWindow.showAtLocation(parentLayout, Gravity.BOTTOM, 0, 0);
} else {
popupWindow.dismiss();
}
}
});
readEmoticons();
enablePopUpView();
checkKeyboardHeight(parentLayout);
enableFooterView();
}
/**
* Reading all emoticons in local cache
*/
private void readEmoticons () {
emoticons = new Bitmap[NO_OF_EMOTICONS];
for (short i = 0; i < NO_OF_EMOTICONS; i++) {
emoticons[i] = getImage((i+1) + ".png");
}
}
/**
* Enabling all content in footer i.e. post window
*/
private void enableFooterView() {
content = (EditText) findViewById(R.id.chat_content);
content.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (popupWindow.isShowing()) {
popupWindow.dismiss();
}
}
});
final Button postButton = (Button) findViewById(R.id.post_button);
postButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (content.getText().toString().length() > 0) {
Spanned sp = content.getText();
chats.add(sp);
content.setText("");
mAdapter.notifyDataSetChanged();
}
}
});
}
/**
* Overriding onKeyDown for dismissing keyboard on key down
*/
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (popupWindow.isShowing()) {
popupWindow.dismiss();
return false;
} else {
return super.onKeyDown(keyCode, event);
}
}
/**
* Checking keyboard height and keyboard visibility
*/
int previousHeightDiffrence = 0;
private void checkKeyboardHeight(final View parentLayout) {
parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView()
.getHeight();
int heightDifference = screenHeight - (r.bottom);
if (previousHeightDiffrence - heightDifference > 50) {
popupWindow.dismiss();
}
previousHeightDiffrence = heightDifference;
if (heightDifference > 100) {
isKeyBoardVisible = true;
changeKeyboardHeight(heightDifference);
} else {
isKeyBoardVisible = false;
}
}
});
}
/**
* change height of emoticons keyboard according to height of actual
* keyboard
*
* #param height
* minimum height by which we can make sure actual keyboard is
* open or not
*/
private void changeKeyboardHeight(int height) {
if (height > 100) {
keyboardHeight = height;
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, keyboardHeight);
emoticonsCover.setLayoutParams(params);
}
}
/**
* Defining all components of emoticons keyboard
*/
private void enablePopUpView() {
ViewPager pager = (ViewPager) popUpView.findViewById(R.id.emoticons_pager);
pager.setOffscreenPageLimit(3);
pager.setBackgroundColor(Color.WHITE);
ArrayList<String> paths = new ArrayList<String>();
for (short i = 1; i <= NO_OF_EMOTICONS; i++) {
paths.add(i + ".png");
}
EmoticonsPagerAdapter adapter = new EmoticonsPagerAdapter(MainActivity.this, paths, this);
pager.setAdapter(adapter);
// Creating a pop window for emoticons keyboard
popupWindow = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT,
(int) keyboardHeight, false);
/*TextView backSpace = (TextView) popUpView.findViewById(R.id.back);
backSpace.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
content.dispatchKeyEvent(event);
}
});*/
popupWindow.setOnDismissListener(new OnDismissListener() {
#Override
public void onDismiss() {
emoticonsCover.setVisibility(LinearLayout.GONE);
}
});
}
/**
* For loading smileys from assets
*/
private Bitmap getImage(String path) {
AssetManager mngr = getAssets();
InputStream in = null;
try {
in = mngr.open("emoticons/" + path);
} catch (Exception e) {
e.printStackTrace();
}
Bitmap temp = BitmapFactory.decodeStream(in, null, null);
return temp;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
#Override
public void keyClickedIndex(final String index) {
ImageGetter imageGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
StringTokenizer st = new StringTokenizer(index, ".");
Drawable d = new BitmapDrawable(getResources(),emoticons[Integer.parseInt(st.nextToken()) - 1]);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
Spanned cs = Html.fromHtml("<img src ='"+ index +"'/>", imageGetter, null);
int cursorPosition = content.getSelectionStart();
content.getText().insert(cursorPosition, cs);
}
}
EDIT:
This is the code for custom keyboard that I have implemented but I am unable to find how to add emoji to that keyboard.
public class SimpleIME extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
private KeyboardView kv;
private Keyboard keyboard;
private View popUpView;
private boolean caps = false;
#Override
public View onCreateInputView() {
kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.qwerty);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
kv.invalidateAllKeys();
popUpView = getLayoutInflater().inflate(R.layout.emoticons_popup, null);
return kv;
}
#Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
playClick(primaryCode);
switch(primaryCode){
case Keyboard.KEYCODE_DELETE :
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
case -80 :
Log.d("smiley", "smiley pressed");
break;
default:
char code = (char)primaryCode;
if(Character.isLetter(code) && caps){
code = Character.toUpperCase(code);
}
ic.commitText(String.valueOf(code),1);
}
}
private void playClick(int keyCode){
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
switch(keyCode){
case 32:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case Keyboard.KEYCODE_DONE:
case 10:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
default: am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
}
}
#Override
public void onPress(int primaryCode) {
}
#Override
public void onRelease(int primaryCode) {
}
#Override
public void onText(CharSequence text) {
}
#Override
public void swipeDown() {
}
#Override
public void swipeLeft() {
}
#Override
public void swipeRight() {
}
#Override
public void swipeUp() {
}
}
EDIT:
Can we copy an image from images list and paste it where keyboard is open??
The best implementation for an emoji keyboard I found was that of sliding emoji-Keyboard
It's a really good implementation, maybe with some redundant code, but still really good for understanding how to implement keyboards that do not fit the normal "button-to-text" keyboards.
UPDATE
Okay, I have now been able to successfully able to integrate the sliding emoji-keyboard into my own project 8Vim after a lot of re-factoring in both of the projects.
Essentially, all you are doing for the emoji keyboard is to create a view of the size of the keyboard and then populating that view with PNG files corresponding to the emoji's. each image acts like a button and delivers the appropriate emoji to the inputConnection.
UPDATE 2
I have extended the sliding emoji-keyboard and created a much cleaner version that should be easier to understand. Take a look at my emoji-keyboard
I am just drawing a Circle with canvas, and change the radius with a SeekBar. This Code works fine on Emulator, but on my phone the remove View thing doesn't work. Means the circle gets bigger and bigger, but not smaller on my phone.
What is the problem here ?
my Code:
public class Kreis extends Activity implements OnSeekBarChangeListener {
private SeekBar seekbar;
public static int radius = 30;
private TextView textview;
private static View alterKreis;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kreis);
this.seekbar = (SeekBar)findViewById(R.id.radiusbar);
this.textview = (TextView)findViewById(R.id.ausgabe);
seekbar.setOnSeekBarChangeListener(this);
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
radius = seekbar.getProgress();
textview.setText(radius + "");
RelativeLayout lp=new RelativeLayout(this);
Circle view = new Circle(this);
lp.removeView(view);
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
addContentView(view,params);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public class Circle extends View{
public Circle(Context context) {
super(context);
}
#Override
public void draw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.GREEN);
// if(radius>0){
canvas.drawCircle(200,200,radius,paint);
// }
}
}
}
when findsellectedtBt() called invalidate in the findSellectedBt() don't work.
so onDraw() is not called.
why these codes don't work correctly ?
public class CustomView extends View {
private Typeface t;
private Paint paint;
private Buttons sellectedBt;
public CustomView(Context context) {
... }
public CustomView(Context context, AttributeSet attrs) {
...}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
...}
#Override
protected void onDraw(Canvas canvas) {
if(isInEditMode()) return ;
canvas.drawColor(Color.YELLOW);
switch(sellectedBt) {
case ID:
t = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
paint.setTypeface(t);
canvas.drawText("ID: 0000", 50, 100, paint);
case PHOTO:
break;
case LINE:
break;
default:
break;
}
}
public void findSellectedBt(Buttons buttonId ) {
sellectedBt = buttonId;
invalidate();
}
}
public class MainActivity extends Activity {
private CustomView customView;
private Button btId;
private CheckBox btPhoto;
private ToggleButton btLineOff;
private Button btClaer;
private ToggleButton btBlue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customView = new CustomView(this);
btId = (Button)findViewById(R.id.id);
btPhoto = (CheckBox)findViewById(R.id.photo);
btId.setOnClickListener(new OnClickListener() {
public void onClick(View v){
System.out.println("idOnclick");
customView.findSellectedBt(Buttons.ID);
}
});
btPhoto.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
System.out.println("photoChecked");
if(arg1 == true)
customView.findSellectedBt(Buttons.PHOTO);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
package com.example.hw4_200921275;
public enum Buttons {ID, PHOTO, LINE, CLEAR, BLUE}
Double check you're somewhere calling
findSellectedBt(buttonsObject);
By the way, notice the typo in Sellected.
I want to do the drag and drop operation in android web view for the images in the webpages.
Code is like this.
WebView webView;
ImageView imageView;
ImageView shadowImageView;
private static final String IMAGEVIEW_TAG = "icon bitmap";
public static final String TAG="ResourceSharing";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browser);
webView=(WebView) findViewById(R.id.webView);
imageView=(ImageView) findViewById(R.id.downloadImage);
webView.setWebViewClient(new WebViewController());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.picasaweb.google.com");
webView.clearCache(true);
webView.setOnLongClickListener(this);
shadowImageView=new ImageView(this);
shadowImageView.setImageBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.picasa_logo));
shadowImageView.setTag(IMAGEVIEW_TAG);
}
public class WebViewController extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
#Override
public boolean onLongClick(View v) {
HitTestResult hitTestResult=webView.getHitTestResult();
Log.i(TAG, "Hit type"+hitTestResult.getType());
switch (hitTestResult.getType()) {
case HitTestResult.IMAGE_TYPE:
Log.i(TAG, "Ïnside image type");
imageView.setVisibility(View.VISIBLE);
break;
case HitTestResult.IMAGE_ANCHOR_TYPE:
Log.i(TAG, "Ïnside image type");
imageView.setVisibility(View.VISIBLE);
break;
case HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
Log.i(TAG, "Ïnside image type");
imageView.setVisibility(View.VISIBLE);
performDragAndDropOperation();
break;
default:
break;
}
return true;
}
#TargetApi(11)
private void performDragAndDropOperation(){
ClipData.Item item = new ClipData.Item((CharSequence) shadowImageView.getTag());
ClipData dragData = new ClipData((CharSequence) shadowImageView.getTag(),new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },item);
DragShadowBuilder shadowBuilder = new MyDragShadowBuilder(shadowImageView);
shadowImageView.startDrag(dragData, shadowBuilder, null, 0);
}
private static class MyDragShadowBuilder extends View.DragShadowBuilder {
private static Drawable shadow;
public MyDragShadowBuilder(View v) {
super(v);
shadow = new ColorDrawable(Color.LTGRAY);
}
#Override
public void onProvideShadowMetrics (Point size, Point touch){
int width;
int height;
Log.i(TAG, "calling getVIew" +getView());
width = getView().getWidth() / 2;
height = getView().getHeight() / 2;
shadow.setBounds(0, 0, width, height);
size.set(width, height);
touch.set(width / 2, height / 2);
Log.i(TAG, "calling getVIew" +getView());
}
#Override
public void onDrawShadow(Canvas canvas) {
Log.i(TAG, "calling getVIew" +getView());
shadow.draw(canvas);
}
}
But when i run the application and try to drag an image after long press an error is coming in the logcat unable to initiate drag in andriod with null pointer exception.
Looking for help
This might seem like a silly qustion but how do you change the picture that draws on the screen.I have already been able to program a app were it draws a little icon where you touch the screen.So natually after I completed that I want to make it better by adding a option menu and the ability to change what icon you were being drown but when I ran the code the icon picture stayed the same.When I looked at it I found that when you click on any of the menu item it does do it's job and change the image id but when you go back to the main screen and try to create a new image it revertes back to the old image.I have no idea why it doesn't change because when I look at it everything make sense for it to change icon properly.If any one has any idea on what i am doing wrong or any suggestion on how to do this it would be greatly appreciate
Main
public class main extends Activity {
/** Called when the activity is first created. */
MenuItem item2;
int item3=R.drawable.ic_launcher;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout sv = new FrameLayout(this);
LinearLayout ll = new LinearLayout(this);
Panel test = new Panel(this);
//ImageButton button = new ImageButton(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(test);
//ll.addView(button);
sv.addView(ll);
setContentView(sv);
}
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
Log.v("test", "item3 before is: "+item3);
item3=R.drawable.box;
Log.v("test", "item3 after is: "+item3);
return super.onOptionsItemSelected(item);
}
}
Panel
public class Panel extends SurfaceView implements SurfaceHolder.Callback {
private Bitmap image;
private ViewThread mThread;
private int x;
private int y;
private ArrayList<Element> mElements = new ArrayList<Element>();
public Panel(Context context) {
super(context );
image = BitmapFactory.decodeResource(getResources(),yantz.imageapp4.R.drawable.test);
getHolder().addCallback(this);
mThread = new ViewThread(this);
}
public void doDraw(Canvas canvas) {
canvas.drawColor(Color.CYAN);
canvas.drawBitmap(image, x, y, null);
synchronized (mElements){
for(Element element : mElements){
element.doDraw(canvas);
}
}
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
Log.v("test", "you have touched the sreen: ");
synchronized (mElements){
mElements.add(new Element(getResources(),(int) event.getX(),(int) event.getY()));
}
return super.onTouchEvent(event);
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
if (!mThread.isAlive()) {
mThread = new ViewThread(this);
mThread.setRunning(true);
mThread.start();
}
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (mThread.isAlive()) {
mThread.setRunning(false);
}
}
}
Elements
public class Element extends main{
private int mX;
private int mY;
int location ;
private Bitmap mBitmap;
public Element(Resources res, int x, int y) {
Log.v("element", "item3 before location is: "+item3);
location =item3;
mBitmap = BitmapFactory.decodeResource(res, location);
mX = x - mBitmap.getWidth() / 2;
mY = y - mBitmap.getHeight() / 2;
Log.v("element", "item3 before location is: "+item3);
}
public void doDraw(Canvas canvas) {
canvas.drawBitmap(mBitmap, mX, mY, null);
}
public void setlocation(int location2){
location=location2;
}
}
ViewThread
public class ViewThread extends Thread {
private Panel mPanel;
private SurfaceHolder mHolder;
private boolean mRun = false;
public ViewThread(Panel panel) {
mPanel = panel;
mHolder = mPanel.getHolder();
}
public void setRunning(boolean run) {
mRun = run;
}
#Override
public void run() {
Canvas canvas = null;
while (mRun) {
canvas = mHolder.lockCanvas();
if (canvas != null) {
mPanel.doDraw(canvas);
mHolder.unlockCanvasAndPost(canvas);
}
}
}
}
you can use
#Override
protected void onResume() {
super.onResume();
id="what ever you want";
//and set it to imagevIew;
}
if i have understood the uestion correctly,this happens because your activity pauses when it is not focused and resumes with default values.