进度对话框中的AsyncTask不显示 [英] Progress dialog not showing in AsyncTask
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/9623470/android-heavy-db-operations-with-progress-dialog\">Android:与进度对话框重DB操作
块引用>我有一个巨大的,我正在尝试插入的SQLite数据库字符串数组。由于这个原因,我现在用的<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction%28%29\"相对=nofollow>成语的BeginTransaction在我的
doInBackground
,它完美的作品。问题是,ProgressDialog是的不可以被显示。可能是什么问题?是不是因为工作的BeginTransaction只有在EXCLUSIVE模式?任何帮助是AP preciated。谢谢!@覆盖
公共无效的onCreate(SQLiteDatabase数据库){
database.execSQL(Constants.CREATE_TABLE_DICT);
mDatabase =数据库;
READFILE(R.raw.dict);
新initdb的()执行();
} 公共类initdb的扩展的AsyncTask&LT;太虚,太虚,太虚&GT; {
InsertHelper IH;
INT wordColumn;
私人ProgressDialog mProgD; @覆盖
在preExecute保护无效(){
super.on preExecute();
mProgD = ProgressDialog.show(mContext,,等待,TRUE); //没有显示!
IH =新InsertHelper(mDatabase,字典);
wordColumn = ih.getColumnIndex(字);
} @覆盖
保护无效doInBackground(虚空...... PARAMS){
mDatabase.beginTransaction();
尝试{
。的String [] SS = mWords.toString()分裂(\\\\ |);
的for(int i = 0; I&LT; ss.length;我++){
IH prepareForInsert()。
串词= SS [I]
ih.bind(wordColumn,字);
ih.execute();
} mDatabase.setTransactionSuccessful();
} {最后
mDatabase.endTransaction();
} 返回null;
} @覆盖
保护无效onPostExecute(虚空结果){
super.onPostExecute(结果);
mProgD.dismiss();
}
}编辑:
这里就是上下文来自://构造
公共AppDatabase(上下文的背景下){
超(背景下,Constants.DATABASE_NAME,空,Constants.DATABASE_VERSION);
mContext =背景;
}
解决方案我找到了答案!查看<一个href=\"http://stackoverflow.com/questions/9623470/android-heavy-db-operations-with-progress-dialog/9629678#9629678\">this链接。再次感谢任何人谁帮助!
Possible Duplicate:
Android: Heavy DB operations with progress dialogI have a huge array of Strings which I'm trying to insert into the sqlite DB. Due to this, I am using the begintransaction idiom in my
doInBackground
, which works perfectly. The problem is that the ProgressDialog is not being shown. What could be the problem? Is it because beginTransaction works only in EXCLUSIVE mode? Any help is appreciated. Thanks!@Override public void onCreate(SQLiteDatabase database) { database.execSQL(Constants.CREATE_TABLE_DICT); mDatabase = database; readFile(R.raw.dict); new InitDB().execute(); } public class InitDB extends AsyncTask<Void, Void, Void> { InsertHelper ih; int wordColumn; private ProgressDialog mProgD; @Override protected void onPreExecute() { super.onPreExecute(); mProgD = ProgressDialog.show(mContext, "", "Wait", true);//NOT BEING SHOWN! ih = new InsertHelper(mDatabase, "dictionary"); wordColumn = ih.getColumnIndex("word"); } @Override protected Void doInBackground(Void... params) { mDatabase.beginTransaction(); try { String [] ss = mWords.toString().split("\\|"); for(int i=0; i<ss.length; i++) { ih.prepareForInsert(); String word = ss[i]; ih.bind(wordColumn, word); ih.execute(); } mDatabase.setTransactionSuccessful(); } finally { mDatabase.endTransaction(); } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); mProgD.dismiss(); } }
EDIT: Here's where the context comes from:
//Constructor public AppDatabase(Context context) { super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION); mContext = context; }
解决方案I found the answer! Check out this link. Thanks again for anybody who helped!
这篇关于进度对话框中的AsyncTask不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!