Thanks brother elder sister



Public class MainActivity extends the Activity {
Final static int CANSHU=1;
Public Handler mHandler=new Handler () {
Public void handleMessage (Message MSG) {
The switch (MSG. What) {
Case CANSHU: strings str1=MSG. GetData (). Get String (" text1 ");//accept MSG passed the parameters of the
String str2=MSG. GetData (). Get String (" text2 ");//accept MSG passed the parameters of the
InitFinishMainActivity (str1, str2);
break;
Default: break;
}
}
};
@ Override
Public void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
InitMainActivity ();
}
Public void InitMainActivity ()
{
The setContentView (new MainActivityView (this, this));
}
Public void initFinishMainActivity (String str1, String str2)
{
Toast. MakeText (MainActivity. This, str1 + str2, Toast. LENGTH_LONG), show ();
Finish ();
}
}
Public class MainActivityView extends the View {
Private MainActivity activity;
Private Context Context;
Private Bitmap m_Bitmap;
Public MainActivityView (Context Context, MainActivity activity) {
Super (context);
Enclosing the activity=activity;
Enclosing context=context;
InitBitmap ();
}
Public void initBitmap ()
{
M_Bitmap=BitmapFactory. DecodeResource (enclosing getResources (), R.d. Rawable ic_launcher);
}
@ Override
Public void ontouch (Canvas, Canvas) {
Canvas. DrawBitmap (m_Bitmap, 0, 0, null);
}
@ Override
Public Boolean onTouchEvent (MotionEvent event) {
Int x=(int) event. GetX ();
Int y=(int) event. GetY ();
The Rect the Rect.
The rect=new the rect (0,0,320,480);
If (the rect. The contains (x, y))
{
The Message MSG=new Message ();
MSG. What=MainActivity. CANSHU;
Bundle Bundle=new Bundle ();
Bundle. PutString (" text1 ", "examples of message passing parameters of daming!" );//to store data in Bundle
Bundle. PutString (" text2 ", "Time: 2011-09-05");//to put data in Bundle
MSG. SetData (bundle);//mes transfer data using Bundle
Activity. The mHandler. SendMessage (MSG);//the activity of the handler sends the message
}
Return super. OnTouchEvent (event);
}
}


CodePudding user response:
This interface do good
CodePudding user response:
The Message MSG=new Message ();MSG. What=MainActivity. CANSHU;
MSG. I use another sign, and then switch case processing in handleMessage
CodePudding user response: