}<br style="word-wrap:break-word;">
class MyThread extends Thread<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
public void run()<br style="word-wrap:break-word;">
{ Canvas canvas = holder.lockCanvas(); Paint paint = new Paint();paint.setColor(Color.YELLOW); canvas.drawRect(100, 100, 200, 200, paint);<br style="word-wrap:break-word;">
holder.unlockCanvasAndPost(canvas);<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
public void surfaceCreated(SurfaceHolder holder) {<br style="word-wrap:break-word;">
new MyThread().start();<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
public void surfaceDestroyed(SurfaceHolder holder) {}<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
30 android 获得控件findViewById<br style="word-wrap:break-word;">
TextView textView = (TextView) findViewById(R.id.TextView01);<br style="word-wrap:break-word;">
31 android 十六进制设置画笔颜色<br style="word-wrap:break-word;">
Paint paint = new Paint();<br style="word-wrap:break-word;">
paint.setColor(0xffffffff);//第一个ff是透明度的设置。<br style="word-wrap:break-word;">
32 android 获得String.xml中配置的字符串<br style="word-wrap:break-word;">
//在activity中直接调用<br style="word-wrap:break-word;">
getText(R.string.app_name);<br style="word-wrap:break-word;">
33 android 去掉应用程序头部<br style="word-wrap:break-word;">
requestWindowFeature(Window.FEATURE_NO_TITLE);<br style="word-wrap:break-word;">
34 android 使用SharedPreferences写入数据代码<br style="word-wrap:break-word;">
getSharedPreferences("data", 0).edit().putString("aa","bb").commit();<br style="word-wrap:break-word;">
35 android 使用SharedPreferences读取数据代码<br style="word-wrap:break-word;">
String data = getSharedPreferences("data", 0).getString("item","");//后面的""是默认值,没有取到则赋值为"",如果不想有默认,可以设置null。<br style="word-wrap:break-word;">
36 android 继承SQLiteOpenHelper<br style="word-wrap:break-word;">
class MyHelper extends SQLiteOpenHelper<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
public MyHelper(Context context, String name, CursorFactory factory,int version) {<br style="word-wrap:break-word;">
super(context, name, factory, version);<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
public void onCreate(SQLiteDatabase db) <br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
db.execSQL(<br style="word-wrap:break-word;">
"CREATE TABLE IF NOT EXISTS testtable (" +<br style="word-wrap:break-word;">
"cardno integer primary key," +<br style="word-wrap:break-word;">
"username varchar," + <br style="word-wrap:break-word;">
"money integer"+<br style="word-wrap:break-word;">
")");<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
db.execSQL("DROP TABLE IF EXISTS testtable");<br style="word-wrap:break-word;">
onCreate(db);<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
37 android 利用SQLiteOpenHelper打开数据库<br style="word-wrap:break-word;">
MyHelper dbHelper = new MyHelper(this, "testtable.db", null, 1);<br style="word-wrap:break-word;">
SQLiteDatabase db = dbHelper.getReadableDatabase();//打开只读<br style="word-wrap:break-word;">
//或者<br style="word-wrap:break-word;">
SQLiteDatabase db = dbHelper.getWritableDatabase();//打开可写<br style="word-wrap:break-word;">
38 android 查询数据表并显示结果<br style="word-wrap:break-word;">
Cursor cursor = db.query("testtable", null, null, null, null, null, null);<br style="word-wrap:break-word;">
//db的获得请参见“利用SQLiteOpenHelper打开数据库”<br style="word-wrap:break-word;">
while(!cursor.isAfterLast()){<br style="word-wrap:break-word;">
Log.i("test",cursor.getString(0));<br style="word-wrap:break-word;">
cursor.moveToNext();<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
39 android Logcat输出打印测试信息<br style="word-wrap:break-word;">
Log.i("TAG","TEST");<br style="word-wrap:break-word;">
40 android 数据表插入数据<br style="word-wrap:break-word;">
ContentValues values = new ContentValues();<br style="word-wrap:break-word;">
values.put("username","admin");<br style="word-wrap:break-word;">
values.put("money","10000");<br style="word-wrap:break-word;">
db.insert("testtable", null, values);<br style="word-wrap:break-word;">
41 android 使得应用全屏<br style="word-wrap:break-word;">
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN,WindowManager.LayoutParams. FLAG_FULLSCREEN); <br style="word-wrap:break-word;">
42 android 设置LinearLayout方向为竖<br style="word-wrap:break-word;">
layoutParant.setOrientation(LinearLayout.VERTICAL);<br style="word-wrap:break-word;">
43 android 设置LinearLayout方向为横<br style="word-wrap:break-word;">
layoutParant.setOrientation(LinearLayout.HORIZONTAL);<br style="word-wrap:break-word;">
44 android 数据库更新数据<br style="word-wrap:break-word;">
ContentValues values = new ContentValues();<br style="word-wrap:break-word;">
values.put("username","admin");<br style="word-wrap:break-word;">
values.put("money","10000");<br style="word-wrap:break-word;">
db.update("testtable",values,"userno=1",null);<br style="word-wrap:break-word;">
45 android 数据库删除数据<br style="word-wrap:break-word;">
db.delete("testtable","userno=1",null);<br style="word-wrap:break-word;">
46 android 判断sd卡是否存在<br style="word-wrap:break-word;">
if (android.os.Environment.getExternalStorageState().equals( <br style="word-wrap:break-word;">
android.os.Environment.MEDIA_MOUNTED))<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
Log.i("test","SDCARD exists");<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
else {<br style="word-wrap:break-word;">
Log.i("test","SDCARD doesn't exist");<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
47 android 创建ImageView<br style="word-wrap:break-word;">
ImageView view = new ImageView(this); <br style="word-wrap:break-word;">
Back to home |
File page
Subscribe |
Register |
Login
| N