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);?? ??? ?//創(chuàng)建或打開數(shù)據(jù)庫?? ??? ?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("數(shù)據(jù)庫打開失敗!");?? ??? ??? ??? ?else?? ??? ??? ??? ??? ?m_textview1.setText("數(shù)據(jù)庫打開成功!");?? ??? ??? ?}?? ??? ??? ?private SQLiteDatabase OpenOrCreateDB() {?? ??? ??? ??? ?SQLiteDatabase dbSQLiteDatabase=null;?? ??? ??? ??? ?try{?? ??? ??? ??? ??? ?dbSQLiteDatabase=SQLiteDatabase.openOrCreateDatabase("/data/data/com.example.demo_01/xiao.db",null);?? ??? ??? ??? ??? ?//以讀寫方式打開數(shù)據(jù)庫?? ??? ??? ??? ?}?? ??? ??? ??? ?catch(Exception ex){?? ??? ??? ??? ??? ?return null;?? ??? ??? ??? ?}?? ??? ??? ??? ?return dbSQLiteDatabase;?? ??? ??? ??? ??? ??? ?}?? ??? ?});
1 回答
已采納

yanrun
TA貢獻(xiàn)317條經(jīng)驗(yàn) 獲得超240個(gè)贊
這是設(shè)置了一個(gè)常量為了增加程序的可讀性,這么做以后維護(hù)的人會(huì)理解起來更容易。
添加回答
舉報(bào)
0/150
提交
取消