public SQLiteDatabase db;
public Cursor cursor;
public SimpleCursorAdapter Adapter = null;
public SimpleCursorAdapter AdapterStomach = null;
private ListView lv;
private LayoutInflater mInflater;
private boolean mLockListView;
public static final String ROOT_DIR = "/data/data/com.romen.CancerAdvice/databases/";
ProductDBHelper mHelper;
public void setDB() {
File folder = new File(ROOT_DIR);
folder.mkdir();
if (folder.exists()) {
} else {
folder.mkdirs();
}
AssetManager assetManager = getResources().getAssets();
File outfile = new File(ROOT_DIR + "test.db"); // --폰에 위치할 경로
InputStream is = null;
FileOutputStream fo = null;
long filesize = 0;
try {
// --asset 폴더 및 복사할 DB 지정
is = assetManager.open("test.db", AssetManager.ACCESS_BUFFER);
filesize = is.available(); // --사이즈 검증
// 파일이 없거나 패키지 폴더에 설치된 DB파일이 포함된 DB파일 보다 크기가 같지않을 경우 DB파일을 덮어 쓴다.
if (outfile.length() <= 0) {
byte[] tempdata = new byte[(int) filesize];
is.read(tempdata);
is.close();
outfile.createNewFile();
fo = new FileOutputStream(outfile);
fo.write(tempdata);
fo.close();
} else {
// Toast.makeText(this, "db있음", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
Toast.makeText(this, "db이동실패", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
setDB();
super.onCreate(savedInstanceState);
setContentView(R.layout.search_test);
mHelper = new ProductDBHelper(this);
db = mHelper.getWritableDatabase();
cursor = db.rawQuery("SELECT * FROM test ", null);
startManagingCursor(cursor);
ListView lv=(ListView)findViewById(R.id.list);
AdapterStomach = new SimpleCursorAdapter(test.this,
R.layout.mylist, cursor, new String[] { "year","title2","content1" },
new int[] { R.id.text1, R.id.text2, R.id.text3 });
System.out.println("AdapterStomach:::"+AdapterStomach);
mLockListView = true;
// 푸터를 등록. setAdapter 이전에 해야함.
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
lv.addFooterView(mInflater.inflate(R.layout.listview_footer, null));
// 스크롤 리스너 등록
lv.setOnScrollListener(this);
lv.setAdapter(AdapterStomach);
lv.setTextFilterEnabled(true);
}
class ProductDBHelper extends SQLiteOpenHelper {
public ProductDBHelper(Context context) {
super(context, "test.db", null, 1);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
public void onBtnClickBackBtn(View _view)
{
finish();
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
// 현재 가장 처음에 보이는 셀번호와 보여지는 셀번호를 더한값이
// 전체의 숫자와 동일해지면 가장 아래로 스크롤 되었다고 가정합니다.
int count = totalItemCount - visibleItemCount;
if(firstVisibleItem >= count && totalItemCount != 0 && mLockListView == false)
{
Log.i("list", "Loading next items");
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
}
}