こんにちは、スタックオーバーフローでの最初の質問です。何か間違っていたらごめんなさい。
私の問題は、アプリを初めて起動するときに、データベースに SQL データを書き込む必要があることです。SQLの書き込み中にonCreate()でそれを行うと、ビューが表示されないため、フリーズするようになります。そして、そこにローダーを作成すると、最初にすべての oncreate を終了し、その後ビューを表示する必要があるため、表示されません。次に、SQLが空の場合にAlertDialogを実行して、「インストール」が必要であることをユーザーに通知し、確認後、実行中にSQLを挿入してロードボックスを作成したかった...
だから私の質問は次のとおりです:onCreateをロードする方法...アクティビティの実行時に...良いアイデアを教えてください...ここに私が作成したコードがあります:
private DatabaseHandler db = new DatabaseHandler(this);
Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context = this;
if(db.getWordsCount() == 0)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Instalation needed");
builder.setMessage("Database need to be installed");
builder.setPositiveButton("Ok", dialogClickListener);
builder.setNegativeButton("Close", dialogClickListener);
builder.show();
}
}
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
ProgressDialog progress = new ProgressDialog(context);
progress.setTitle("Instalation");
progress.setMessage("Please wait...");
progress.show();
db.insertWords(db);
progress.cancel();
break;
case DialogInterface.BUTTON_NEGATIVE:
finish();
break;
}
}
};