import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class StageDialog extends Dialog {
EditText edtName;
Button btnConfirm, btnCancel;
// StageSelectActivity stageSelectActivity;
Handler handler;
Context context;
// DBHelper myHelper = new DBHelper(this);
DBHelper helper = new DBHelper(context);
SQLiteDatabase db;
String name;
public StageDialog(Context context/*, StageSelectActivity s*/) {
super(context);
// TODO Auto-generated constructor stub
this.context = context;
// stageSelectActivity = s; // 생성자 오버라이딩
}
public String getName(String name) {
return name;
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stagedialog);
handler = new Handler();
edtName = (EditText)findViewById(R.id.EdtName);
btnConfirm = (Button)findViewById(R.id.BtnConfirm);
btnCancel = (Button)findViewById(R.id.BtnCancel);
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// MySQLite mysql = new MySQLite(context, null, null, 0);
handler.post(new Runnable() { // 액티비티 아닌곳에서 액티비티 사용할때 handler를 사용하여 접근
@Override
public void run() {
// TODO Auto-generated method stub
db = helper.getWritableDatabase();
name = edtName.getText().toString();
String sql = "INSERT INTO PipeTBL" + " VALUES('"+ name+ "', 3);";
db.execSQL(sql);
db.close();
Intent intent = new Intent(context.getApplicationContext(), GameActivity.class);
context.startActivity(intent);
// stageSelectActivity.finish();
}
});
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dismiss();
}
});
}
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "groupDB", null, 1);
}
public void onCreate(SQLiteDatabase db) {
// db.execSQL("create table groupTBL(gName char(20) primary key, gNumber integer);");
String createSql = "CREATE TABLE PipeTBL" + " ("
+ "id Int NOT NULL AUTOINCREMENT PRIMARY KEY, " + "name Text, "
+ "time Int)";
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if existes group");
onCreate(db);
}
}
}
SQLite를 이용해서 이름을 입력받고 버튼을 누르고 다음으로 넘어가게 해주려고 합니다..
근데 이름을 입력하고 버튼을 누르는 순간 앱이 오류나면서 종료가 됩니다...
어디를 어떻게 수정해야 좋을지 조언 부탁드립니다.