android期末考大题(沈阳师范大学)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.SQLite数据库

public class MySqliteDB extends SQLiteOpenHelper { public MySqliteDB(Context context, String name, CursorFactory factory,int version) {

super(context, name, factory, version);}

public void onCreate(SQLiteDatabase db) {

db.execSQL("create table if not exists people ("+"pid integer primary key,"+

"pname text,"+"page integer)");}

public void onUpgrade(SQLiteDatabase db,

int oldVersion, int newVersion) {}}

public class MainActivity extends Activity {

Button btn;MySqliteDB mydb;

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(yout.activity_main);

mydb=new MySqliteDB(this, "MyDB", null, 1);

btn=(Button)findViewById(R.id.btn);

btn.setOnClickListener(new OnClickListener() { public void onClick(View v) {

SQLiteDatabase db=mydb.getReadableDatabase();}});} public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu);

return true;}}

2.添加ToggleButton

public class Example_55 extends Activity{

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

setContentView(yout.main);

ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);

toggleButton.setChecked(true);

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_height="wrap_content"

android:layout_marginLeft="30dp"

android:textOff="打开电灯"

android:textOn="关闭电灯" />

3.Spinner下拉列表框

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

public class Example_58 extends Activity{

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(yout.main);

Spinner spinner= (Spinner) findViewById(R.id.spinner); ArrayAdapter aAdapter=ArrayAdapter.createFromResource(this, R.array.color,t,yout.simple_spinner_item); Adapter.setDropdownViewResource

(yout.simple_spinner_dropdown_item);

spinner.setAdapter(aAdapter);

OnItemSelectedListener=new OnItemSelectedListener(){

public void onItemSelected(AdapterView parent, View view, int position, long id){

Toast.makeText(Example_59.this,"选择的色彩:"+

parent.getItemAtPosition(position).toString(),

Toast.LENGTH_LONG).show;}

public void onNothingSelected(AdapterView parent){

Toast.makeText(Example_59.this,"Nothing is selected",

Toast.LENGTH_LONG).show;}};

Spinner.SrtOnItemSelectedListener(itemSelectedListener);}}

4.爱好

浙江

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="用户名">

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

相关文档
最新文档