2011年2月20日 星期日

android 程式設計小抄 (語法筆記) 陸續更新!!

AndroidManifest.xml



        
            
                
                
            
        
        
        
    


解說:
android:icon="@drawable/icon"
定義程式的圖示 @drawable/+【res/drawable下的檔名】

< activity android:name="Hello"
name="Java Class檔名"

< category android:name="android.intent.category.LAUNCHER"
表示這個 activity 是程式預設開啟的畫面。


增加彈出對話框

AlertDialog.Builder dialog1 = new AlertDialog.Builder(Hello.this);

dialog1.setTitle(R.string.aboutUs_Title).setMessage(R.string.aboutUs_Content);

dialog1.setPositiveButton(R.string.buttonText_Confirm, new DialogInterface.OnClickListener(){
       public void onClick(DialogInterface arg0, int arg1) {
          ;
      }
});

dialog1.show();


按下Menu 時出現選單。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, MENU_1, 0, R.string.aboutUs).setIcon(R.drawable.aboutus);
        menu.add(0, MENU_2, 1, R.string.homePageLable).setIcon(R.drawable.www);
        return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
      switch(item.getItemId()){
             case MENU_1:
                    createAlertDialog();
                    break;
             case MENU_2:
                    finish();
                    break;
     }
     return super.onOptionsItemSelected(item);
}


按下呼叫另一個 Intent

1.  呼叫自己所撰寫的 activity
Intent intent = new Intent();
intent.setClass(Hello.this, Second.class);
intent.putExtra("TEXT", getResources().getString(R.string.aboutUs_Content));
startActivity(intent);

2. 呼叫其他以註冊的程式
Uri homePageUri = Uri.parse("http://www.mobile01.com/");
Intent intent = new Intent(Intent.ACTION_VIEW,homePageUri);
startActivity(intent);



註冊事件
button_add.setOnClickListener(addFunction);

private OnClickListener addFunction = new OnClickListener(){
         public void onClick(View arg0) {
                // 想做的事           
         }
};

沒有留言: