Android 实验报告 Sqlite 数据库操作

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
android:onClick="exam"/>
<TextView
android:text="开始考试" />
</LinearLayout>
···
</LinearLayout>
EntryActivity.java:
public class EntryActivity extends Activity {
public String B;
public String C;
public String D;
public String answer;
question(int id,String content,String a,String b,String c,String d,String answer){···}
}
public static Map<Integer,question> question_items_map =
new HashMap<Integer,question>();
static {
addItem( new question(1,"1.JavaScript执行表单验证···。","A)···","B)···","C)···","D)···","a"));
intent.putExtra("user",username);
startActivity(intent);
}else{
Toast.makeText(LoginActivity.this,"不可以登录",Toast.LENGTH_SHORT).show();
}
}
});
}
}
content_entry.xml:
Button login = (Button)findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = ((EditText)findViewById(R.id.username)).getText().toString();
new String[]{username,password});
if(cursor.getCount() != 0){
Toast.makeText(LoginActivity.this,"可以登录",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this,EntryActivity.class);
String username = ((EditText)findViewById(R.id.username)).getText().toString();
String password = ((EditText)findViewById(R.id.password)).getText().toString();
Android平台开发基础
实验报告
实验名称
实验四AndroidSQLite数据库应用
日期
2016-05-14
专业班级
计算机133班
地点Baidu Nhomakorabea
信息学院M601
实验人
学号
12
同组人
单独完成
一、
(1)熟悉Android的文件操作
(2)掌握AndroidSQLite数据库
(3)熟悉XML和JSon文件读取
二、
1、熟练使用Android的项目创建;
+ ")";
db.execSQL(sql);
sql = "insert into user_info values( null,?,?)";
db.execSQL(sql,new String[]{username,password});
Toast.makeText(RegisterActivity.this,"注册成功,请登录",Toast.LENGTH_SHORT).show();
try{
String sql = "create table if not exists user_info (_id integer "
+ " primary key autoincrement,"
+ " username varchar(255),"
+ " password varchar(255)"
<TabWidget
android:id="@android:id/tabs"/>
<FrameLayout
android:id="@android:id/tabcontent">
</FrameLayout>
</LinearLayout>
</TabHost>
MainActivity.java:
public class MainActivity extends TabActivity {
···
}
public static void addItem(question q){
question_items_map.put(q.id,q);
};
}
ShowQuestionActivity.java:
public class ShowQuestionActivity extends Fragment{
View rootView = inflater.inflate(R.layout.show_question, container, false);
Question.question question;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getArguments().containsKey("item_id")){
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
/*start code*/
TabHost tabHost = getTabHost();
android:id="@android:id/tabhost"
tools:context="com.example.ydc.filemanager.MainActivity">
<LinearLayout
android:background="@drawable/login_bg"
android:orientation="vertical">
···
public void exit(View v){
finish();
}
}
Question.java:
public classQuestion {
public static class question{
public int id;
public String content;
public String A;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_entry);
/*start code*/
String user = (String) getIntent().getExtras().get("user");
question = Question.question_items_map.get(getArguments().getInt("item_id"));
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
<LinearLayout>
<TextView
android:text="欢迎"/>
<TextView
android:id="@+id/showUser"
android:textColor="#0f40e1"/>
<TextView
android:text="参加考试"/>
</LinearLayout>
String password = ((EditText)findViewById(R.id.password)).getText().toString();
Cursor cursor = db.rawQuery("select username from user_info where username=? and password=?",
super.onCreate(savedInstanceState);
setContentView(R.layout.content_login);
/*start*/
db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir()+"/user.db3",null);
/*添加第一个选项卡*/
TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1");
tab1.setIndicator("login");
tab1.setContent(new Intent(this,LoginActivity.class));
tabHost.addTab(tab1);
/*添加第二个选项卡*/
···
}
RegisterActivity.java:
public class RegisterActivity extends Activity {
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
/**/
Button register = (Button)findViewById(R.id.register);
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}catch (Exception e){
e.printStackTrace();
}
}
});
}
}
LoginActivity.java:
public class LoginActivity extends AppCompatActivity {
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
((TextView)findViewById(R.id.showUser)).setText(user);
}
public void exam(View view){
startActivity(new Intent(EntryActivity.this, ExamActivity.class));
}
2、掌握Android的SQLite数据库设计;
3、掌握Android的Activity和Fragement用法;
4、熟悉XML和JSon文件读取
三、
要求使用SQLite数据库实现用户注册和登录,读取数据库信息,退出时生成XML文件或JSON文件。

content_main.xml:
<TabHost
super.onCreate(savedInstanceState);
setContentView(R.layout.content_register);
/*start*/
db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString()+"/user.db3", null);
<LinearLayout>
<LinearLayout
android:gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:background="@drawable/main_menu_exam"
相关文档
最新文档