Android Application Development notes-project code 3

Source: Internet
Author: User

1.3 App controls
MainActivity. java
[Java]
Package com. example. apppalettesdemo;
 
Import andro
Id. app. Activity;
Import android. app. AlertDialog;
Import android. app. AlertDialog. Builder;
Import android. app. Notification;
Import android. app. icationicationmanager;
Import android. app. PendingIntent;
Import android. app. ProgressDialog;
Import android. content. DialogInterface;
Import android. content. DialogInterface. OnClickListener;
Import android. content. Intent;
Import android. view. Menu;
Import android. view. MenuItem;
Import android. widget. Toast;
 
Public class MainActivity extends Activity implements OnClickListener {
 
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
}
 
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
GetMenuInflater (). inflate (R. menu. my_options_menu, menu );
Return true;
}

@ Override
Public boolean onOptionsItemSelected (MenuItem item ){
// TODO Auto-generated method stub
Boolean flag = false;

Switch (item. getItemId ()){
Case R. id. AlertDialog01:
Builder dialog = new AlertDialog. Builder (MainActivity. this );
Dialog. setTitle ("Hint ");
Dialog. setMessage ("This is Message! ");
Dialog. setPositiveButton ("OK", this );
Dialog. show ();

Flag = true;
Break;
 
Case R. id. icationicationmanager01:
Icationicationmanager notiManager =
(Icationicationmanager) getSystemService (NOTIFICATION_SERVICE );

Notification notiInst = new Notification (
R. drawable. ic_launcher, "This is running y ",
System. currentTimeMillis ());
PendingIntent pendIntent = PendingIntent. getActivity (
This, 0, new Intent (this, MainActivity. class ),
PendingIntent. FLAG_UPDATE_CURRENT );
NotiInst. setLatestEventInfo (this, "Notify", "Notify 01", pendIntent );

NotiManager. Y (0, notiInst );

Flag = true;
Break;

Case R. id. progressDialog01:
ProgressDialog progrDialog = new ProgressDialog (this );
ProgrDialog. setProgressStyle (ProgressDialog. STYLE_SPINNER );
ProgrDialog. setMessage ("Loading Information ...");
ProgrDialog. show ();

Flag = true;
Break;

Default:
Break;
}

Return flag;
}

// DialogInterface
@ Override
Public void onClick (DialogInterface dialog, int which ){
// TODO Auto-generated method stub
Toast. makeText (this, "You just press 'alertdialog 'button! ", Toast. LENGTH_SHORT). show ();
}

}

Package com. example. apppalettesdemo;

Import android. OS. Bundle;
Import android. app. Activity;
Import android. app. AlertDialog;
Import android. app. AlertDialog. Builder;
Import android. app. Notification;
Import android. app. icationicationmanager;
Import android. app. PendingIntent;
Import android. app. ProgressDialog;
Import android. content. DialogInterface;
Import android. content. DialogInterface. OnClickListener;
Import android. content. Intent;
Import android. view. Menu;
Import android. view. MenuItem;
Import android. widget. Toast;

Public class MainActivity extends Activity implements OnClickListener {

@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
}

@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
GetMenuInflater (). inflate (R. menu. my_options_menu, menu );
Return true;
}

@ Override
Public boolean onOptionsItemSelected (MenuItem item ){
// TODO Auto-generated method stub
Boolean flag = false;

Switch (item. getItemId ()){
Case R. id. AlertDialog01:
Builder dialog = new AlertDialog. Builder (MainActivity. this );
Dialog. setTitle ("Hint ");
Dialog. setMessage ("This is Message! ");
Dialog. setPositiveButton ("OK", this );
Dialog. show ();

Flag = true;
Break;

Case R. id. icationicationmanager01:
Icationicationmanager notiManager =
(Icationicationmanager) getSystemService (NOTIFICATION_SERVICE );

Notification notiInst = new Notification (
R. drawable. ic_launcher, "This is running y ",
System. currentTimeMillis ());
PendingIntent pendIntent = PendingIntent. getActivity (
This, 0, new Intent (this, MainActivity. class ),
PendingIntent. FLAG_UPDATE_CURRENT );
NotiInst. setLatestEventInfo (this, "Notify", "Notify 01", pendIntent );

NotiManager. Y (0, notiInst );

Flag = true;
Break;

Case R. id. progressDialog01:
ProgressDialog progrDialog = new ProgressDialog (this );
ProgrDialog. setProgressStyle (ProgressDialog. STYLE_SPINNER );
ProgrDialog. setMessage ("Loading Information ...");
ProgrDialog. show ();

Flag = true;
Break;

Default:
Break;
}

Return flag;
}

// DialogInterface
@ Override
Public void onClick (DialogInterface dialog, int which ){
// TODO Auto-generated method stub
Toast. makeText (this, "You just press 'alertdialog 'button! ", Toast. LENGTH_SHORT). show ();
}

}
 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.