編輯:關於Android編程
1.2 菜單
MainActivity.java
[java]
package com.example.testmenu;
import android.os.Bundle;
import android.app.Activity;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final int MENU_FILE_1 = Menu.FIRST;
private static final int MENU_EXIT_2 = Menu.FIRST + 1;
String[] phones = {
"HTC Rezound", "Samsung Galaxy S II Skyrocket",
"Samsung Galaxy Nexus", "Motorola Droid Razr",
"Samsung Galaxy S", "Samsung Epic Touch 4G",
"iPhone 4S", "HTC Titan"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.list01);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listitem,
phones);
listView.setAdapter(adapter);
registerForContextMenu(listView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.activity_main, menu);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.my_menu, menu);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
if (v.getId() == R.id.list01) {
MenuInflater popmenuInflater = getMenuInflater();
popmenuInflater.inflate(R.menu.pop_menu, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
TextView text = (TextView) findViewById(R.id.footer);
switch (item.getItemId()) {
case R.id.edt01:
text.setText("Edit Selected");
return true;
case R.id.del01:
text.setText("Delete Selected");
return true;
case R.id.about01:
Toast.makeText(this, "This is software author: xiaobin.", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case MENU_FILE_1:
fileMenu();
break;
case MENU_EXIT_2:
exitMenu();
break;
default:
break;
}
return false;
}
private void fileMenu() {
// TODO My-generated method stub
}
private void exitMenu() {
// TODO My-generated method stub
}
}
package com.example.testmenu;
import android.os.Bundle;
import android.app.Activity;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final int MENU_FILE_1 = Menu.FIRST;
private static final int MENU_EXIT_2 = Menu.FIRST + 1;
String[] phones = {
"HTC Rezound", "Samsung Galaxy S II Skyrocket",
"Samsung Galaxy Nexus", "Motorola Droid Razr",
"Samsung Galaxy S", "Samsung Epic Touch 4G",
"iPhone 4S", "HTC Titan"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.list01);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listitem,
phones);
listView.setAdapter(adapter);
registerForContextMenu(listView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.activity_main, menu);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.my_menu, menu);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
if (v.getId() == R.id.list01) {
MenuInflater popmenuInflater = getMenuInflater();
popmenuInflater.inflate(R.menu.pop_menu, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
TextView text = (TextView) findViewById(R.id.footer);
switch (item.getItemId()) {
case R.id.edt01:
text.setText("Edit Selected");
return true;
case R.id.del01:
text.setText("Delete Selected");
return true;
case R.id.about01:
Toast.makeText(this, "This is software author: xiaobin.", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case MENU_FILE_1:
fileMenu();
break;
case MENU_EXIT_2:
exitMenu();
break;
default:
break;
}
return false;
}
www.2cto.com
private void fileMenu() {
// TODO My-generated method stub
}
private void exitMenu() {
// TODO My-generated method stub
}
}
??嵌入式設備的一個普遍特點是內存容量相對有限。當運行的程序超過一定數量時,或者涉及復雜的計算時,很可能出現內存不足,進而導致系統卡頓的現象。Android 系統也不例外
開發之前大約從去年開始吧, 也可能是前年 Html5好像火得不得了, 不得了...總能從網上聽說到 XXX混合開發, 為了緊跟潮流(雖然有點兒晚了), 咱們也看看Andr
最近無聊在做一個項目,需要用到日歷。日歷並不需要太復雜,只需要能夠簡單的查看就行,所以我選用了java提供的Calendar類,和安卓的gridView組合的形式.先看效
通知基本用法通知的必要屬性一個通知必須包含以下三項屬性:小圖標,對應 setSmallIcon()通知標題,對應 setContentTitle()詳細信息,對應 set