概述
【实例简介】
【实例截图】
【核心代码】
package com.example.datastorage;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class AddMsg extends Activity{
private EditText ID;
private EditText Name;
private EditText Birthday;
private Button saveBt;
private Button resetBt;
int i;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_msg);
bindView();
}
public void bindView() {
ID = (EditText) findViewById(R.id.ID);
Name = (EditText) findViewById(R.id.Name);
Birthday = (EditText) findViewById(R.id.Birthday);
saveBt = (Button) findViewById(R.id.saveMsg);
resetBt=(Button) findViewById(R.id.resetMsg);
saveBt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(ID.getText().toString().equals("")||Name.getText().toString().equals("")||
Birthday.getText().toString().equals("")){
new AlertDialog.Builder(AddMsg.this).setTitle(
R.string.notice).setIcon(R.drawable.alert).setMessage(
R.string.warning).setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
}).show();
}
else{
SharedPreferences Msg = getSharedPreferences("StudentMsg", 0);
// 将新目录保存进去
int totalNum=Msg.getInt("totalNum", 0);
totalNum ;
Msg.edit().putInt("totalNum", totalNum).putString("ID" totalNum,
ID.getText().toString()).putString("Name" totalNum,
Name.getText().toString()).putString("Birthday" totalNum,
Birthday.getText().toString()).commit();
ID.setText("");
Name.setText("");
Birthday.setText("");
}
}
});
resetBt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {ID.setText("");
Name.setText("");
Birthday.setText("");}
});
}
@Override
protected void onStop() {
super.onStop();
}
}
最后
以上就是老实砖头为你收集整理的java 安卓 sqlite数据库,android sqlite数据库操作的全部内容,希望文章能够帮你解决java 安卓 sqlite数据库,android sqlite数据库操作所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复