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();

}

猜你喜欢

转载自blog.csdn.net/bigfatdone/article/details/80742941