android考試內容

安卓四大組件:activity content Provider service broadcase Receiver

handler 和 broadcase 都是實現不同線程之間的通信

fileter:過濾  intent:意圖,目的

resume:繼續

四大布局 relativeLayout lilnearLayout absoluteLayout FrameLayout TableLayout

linux內核層 運行庫 運行程序框架層 運行程序層

activity生命週期:oncreat onstart onrestart  onresume(繼續) onpause(暫停) onstop ondestroy

 

service進程:oncreat onstart onbind onunbind onstop ondestroy

context.startservice-->oncreate()-->onstart()-->stopservice()-->ondestroy()

context.bindservice()-->oncreate()-->onbind()-->unbindservice()-->ondestroy()

layout裏面佈局的文件字母都是不能大寫的

基於監聽接口的事件處理

imlpements OnClickListener(單擊事件接口)

Botton button1 = (Button)findViewById(R.id.button);

button1.setOnclicklistener(this);

public void onClick(view v){//基於監聽接口的事件處理

}

事件處理機制都是基於widget框架,比如要往文件裏面加入一個button,需要import Android.widget.Button;

常用的widget組件:button,textView,editView,CheckBox,radioButton,listView,spinner

toast提示信息:toast.makeText(getApplicationContext,"你要的提示信息是"//顯示文本,toast.LENGTH_SHORT//顯示時長).show();

創建intent:

Intent intent = new Intent(源activity.this,目的activity.class);//聲明intent

intent.setclass(this,目的activity.class);//跳轉

startActivity(intent);//啓動跳轉

還需要修改AndroidManifest.xml文件application裏面的<activity android:name=".目的activity名稱"></activity>

bundle傳遞數值:

Bundle bundle = new Bundle();//創建bundle對象

bundle.putSting("name",yy);//賦值

Intent  intent = new Inten(源activity名稱.this,目的activity名稱.class);//創建intent對象

intent.putExtras(bundle);//取出bundle信息

finish();//關閉activity

startActivity(intent);//跳轉

 

目的activity:

Bundle p = getIntent().getBundle();//獲取intent裏面的bundle信息

string  info = p.getSting("name");//獲取name並且把其值賦予info

//可以使用info了,info=yy

SQLite的優點:輕量級,安全性,隔離性,獨立性,跨平臺,支持多種語言,內存數據庫,可變長記錄,訪問簡單

API類:SQLiteOpenHelper,SQLiteOpenHelper類是SQLiteDatabase的一個輔助類

繼承了SQLiteOpenHelper類需要有三大步驟:

①重寫構造方法(與類名一樣)內容public :super(context,“數據庫名”,null,1)

public DatabaseHelper(context context ,string name,cursorFactory factory,int  version){

super(context,name,null,1)

}

②重寫public oncreate(SQLiteDatabase db)

public ocreate(SQLitedatabase db){

db.execSQL(sql);

}

③重寫public onupgrade(SQLitedatabase db,int oldversion,int newversion)

public onupgrade(SQLitedatabase db,int oldversion,int newversion){

db.execSQL(sql);

}

SQLite增加:

public insert(SQLitedatabase db){

db.execSQL("inset into table(id,name,inten) value("2515","yangshan","qishu")")

}

SQLite查詢:

public Cursor select(SQLiteDatabase db){//定義遊標,遍歷表

cursor result = db.rawquery("selecr id ,name,inren from table ")

result.MoveTofirst();

while(!result.isAfterLast()){

int id=result.getInt(0);

string name=result.getString(1);

string inten=result.getString(2);

result.moveToNext();

}

result.close();

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章