1
我正在創建一個登錄應用程序,其中在EditText中輸入的數據將在一個變量中獲得一個單擊java文件中的按鈕,並且該值將存儲到sqlite數據庫中我已經創建,但是當我在EditText中輸入值並單擊按鈕時,我沒有將任何數據庫創建到文件資源管理器中。文件資源管理器dos不顯示任何數據庫
這裏是我的代碼:
import java.util.Locale;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AAAActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText userid = (EditText)findViewById(R.id.et_un);
EditText password = (EditText)findViewById(R.id.et_pw);
final String uid;
final String pwd;
uid = userid.getText().toString();
pwd = password.getText().toString();
Button btn = (Button)findViewById(R.id.btn_login);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
InsertUser(uid, pwd);
show();
}
});
}
public void InsertUser(String user_name, String password){
//SQLiteDatabase db;
SQLiteDatabase db;
db = openOrCreateDatabase("TestData.db", SQLiteDatabase.CREATE_IF_NECESSARY,
null);
try{
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
/*final String CREATE_TABLE_USERS = "CREATE TABLE users (" + "id INTEGER
PRIMARY KEY AUTOINCREMENT,"+" LoginName text not null, Password
text not null);"; */
String CREATE_TABLE_USERS = "CREATE TABLE users (" + "id INTEGER PRIMARY KEY
AUTOINCREMENT,"+" LoginName text not null, Password text not null);";
db.execSQL(CREATE_TABLE_USERS);
ContentValues values = new ContentValues();
values.put("LoginName", user_name);
values.put("Password", password);
db.insert("users", null, values);
}
catch(Exception e){
}
}
public void show(){
Toast toast=Toast.makeText(this, "your data is received", Toast.LENGTH_SHORT);
toast.show();
}
}
我是新的android上。任何幫助表示讚賞。
你可以上傳文件資源管理器的截圖,在你的包內顯示你的數據庫文件夾? – 2012-03-19 07:11:20
請給我你的電子郵件地址Shashank .... – Ashu 2012-03-19 07:25:04
我認爲最終的字符串uid;和最後的絃樂psw;不收集價值............ – Ashu 2012-03-19 07:30:45