android EditText+ListView的组合(类似于AutoCompleteTextView)

分享到:

很好的帖子:

eoeWiki客户端(android版)1.0.0版正式发布~
http://www.eoeandroid.com/thread-194188-1-1.html

Android定时自动启动应用程序应用教程
http://www.eoeandroid.com/thread-194271-1-1.html

基于Android 随手记
http://www.eoeandroid.com/thread-194031-1-1.html

 

因为问这个问题的人很多,所以刚刚找了下代码,结果还手动的把他提取出来。好了废话不多说了。直接上代码。

package ki.test.edit_list;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
 
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
 
public class DBManager {
        private final int BUFFER_SIZE = 40000;
        public static final String DB_NAME = "city.db"; // 保存的数据库文件名
        public static final String PACKAGE_NAME = "ki.test.edit_list";
        public static final String DB_PATH = "/data"
                        + Environment.getDataDirectory().getAbsolutePath() + "/"
                        + PACKAGE_NAME; // 在手机里存放数据库的位置
 
        private SQLiteDatabase database;
        private Context context;
 
        public DBManager(Context context) {
                this.context = context;
        }
 
        SQLiteDatabase db = null;
 
        public SQLiteDatabase getDatabase(){
                try {
                        openDatabase();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                return db;
        }
         
        private void openDatabase() throws IOException {
                String dbfile = DB_PATH + "/" + DB_NAME;
 
                if (!(new File(dbfile).exists())) {// 判断数据库文件是否存在,若不存在则执行导入,否则直接打开数据库
                        InputStream is = this.context.getResources().openRawResource(
                                        R.raw.city); // 欲导入的数据库
                        FileOutputStream fos = new FileOutputStream(dbfile);
                        byte[] buffer = new byte[BUFFER_SIZE];
                        int count = 0;
                        while ((count = is.read(buffer)) > 0) {
                                fos.write(buffer, 0, count);
                        }
                        fos.close();
                        is.close();
                }
 
                db = SQLiteDatabase.openDatabase(dbfile, null,
                                SQLiteDatabase.OPEN_READWRITE);
        }
 
        public void closeDatabase() {
                this.database.close();
        }
         
         
}
昵    称:
验证码:

相关文档: