Ad

Sunday, July 7, 2013

How to copy sqlite db from Asset Folder in Android ?

 1. Put the dbfile in the asset folder.

2. Create an instance to the dbFile.

File dbfile=new File(parentfolder,dbfile); (we can choose any folder as parent folder)

3. Check whether db is existing or not. if not copy it to the folder.

if (!dbfile.exists()) {
try {
copyDatabase(dbfile);
} catch (IOException e) {
throw new RuntimeException("Error creating source database", e);
}
}

private void copyDatabase(File dbFile) throws IOException {
InputStream is = context.getAssets().open(DB_NAME);
OutputStream os = new FileOutputStream(dbFile);
 
byte[] buffer = new byte[1024];
while (is.read(buffer) > 0) {
os.write(buffer);
}
 
os.flush();
os.close();
is.close();
}

Friday, June 28, 2013

Android SQLite Commands with Group By and HAVING

 SELECT * from survey_answer_list_main





SELECT question_id,answer, count(answer)  from survey_answer_list_main where survey_id=1 AND type='single'  group by question_id,answer;

SELECT question_id,answer, count(answer)  from survey_answer_list_main where survey_id=1 AND type='single'  group by question_id,answer having answer LIKE '%yes%'



Friday, June 14, 2013

Multi-Selection ListView ANDROID with CheckBox

Multi selection

http://dj-android.blogspot.in/2012/04/milti-selection-listview-android-with.html

To get the selected rows

del_selected.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
SavelistAdapter sladapt=(SavelistAdapter) list_save.getAdapter();
String inarray="(";
for(int i=0;i<sladapt.getCount();i++){
mItem=sladapt.getItem(i);
if(nm.isChecked()){
inarray+=""+nm.getId()+",";
}

}
inarray=inarray.substring(0, inarray.length()-1)+")";
Log.i("zacharia", "i ="+inarray);
}

});

Monday, June 10, 2013