private SQLiteDatabase m_dbSQLiteDatabase=null;?? ?private TextView m_textview1=null;?? ?private static final int INFORMATIONACT=1;?? ?@Override?? ?protected void onCreate(Bundle savedInstanceState) {?? ??? ?super.onCreate(savedInstanceState);?? ??? ?setContentView(R.layout.activity_main);?? ??? ?Intent intent = new Intent(MainActivity.this,yypService.class); ??? ??? ?startService(intent); ??? ??? ?m_textview1=(TextView)findViewById(R.id.textview1);?? ??? ?//創建或打開數據庫?? ??? ?Button button1=(Button)findViewById(R.id.button1);?? ??? ?button1.setOnClickListener(new OnClickListener(){?? ??? ??? ?public void onClick(View v){?? ??? ??? ??? ?m_dbSQLiteDatabase=OpenOrCreateDB();?? ??? ??? ??? ?if(m_dbSQLiteDatabase==null)?? ??? ??? ??? ??? ?m_textview1.setText("數據庫打開失?。?);?? ??? ??? ??? ?else?? ??? ??? ??? ??? ?m_textview1.setText("數據庫打開成功!");?? ??? ??? ?}?? ??? ??? ?private SQLiteDatabase OpenOrCreateDB() {?? ??? ??? ??? ?SQLiteDatabase dbSQLiteDatabase=null;?? ??? ??? ??? ?try{?? ??? ??? ??? ??? ?dbSQLiteDatabase=SQLiteDatabase.openOrCreateDatabase("/data/data/com.example.demo_01/xiao.db",null);?? ??? ??? ??? ??? ?//以讀寫方式打開數據庫?? ??? ??? ??? ?}?? ??? ??? ??? ?catch(Exception ex){?? ??? ??? ??? ??? ?return null;?? ??? ??? ??? ?}?? ??? ??? ??? ?return dbSQLiteDatabase;?? ??? ??? ??? ??? ??? ?}?? ??? ?});
添加回答
舉報
0/150
提交
取消