我想使用此数据库代码将图像从相机放入数据库。保存按钮和预览按钮的代码应该是什么?
public class databases extends SQLiteOpenHelper {
public static final String data = "student.db";
public static final String TABLE_NAME = "Student_TABLE";
public static final String COL_1 = "Fname";
public static final String COL_2 = "password";
public static final String COL_3 = "Fathers_name";
public static final String COL_4 = "Roll";
public static final String COL_5 = "Image";
public databases(Context context) {
super(context, data, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME + " (Fname TEXT,password TEXT,Fathers_name TEXT,Roll TEXT PRIMARY KEY,Image BLOB)");
}
现在这是包含相应按钮的活动代码。
public class home_page extends AppCompatActivity {
Button lout,homepage,showperson,picture;static final int REQUEST_IMAGE_CAPTURE = 1;
TextView showit;
String userid,pwrd,r2,r3,r4;
databases dbss;
public void getterclass(String m)
{
userid=m;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
lout = (Button) findViewById(R.id.out);
homepage = (Button) findViewById(R.id.home);
showit=(TextView) findViewById(R.id.showtextdata);
showperson=(Button)findViewById(R.id.showdata);
picture=(Button)findViewById(R.id.images);
dbss=new databases(home_page.this);
getSupportActionBar().hide();
homepage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent redirect=new Intent(home_page.this,home_page.class);
startActivity(redirect);
}
});
lout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent logout=new Intent(home_page.this,log_in.class);
startActivity(logout);
}
});
showperson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor sh=dbss.givedata(userid);
StringBuffer buf=new StringBuffer();
buf.append("First name :" + sh.getString(0) + "\n");
buf.append("password :" + sh.getString(1) + "\n");
buf.append("Father's name :" + sh.getString(2) + "\n");
buf.append("Roll :" + sh.getString(3) + "\n\n");
showit.setText(buf.toString());
}
});
picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
databases help=new databases(home_page.this);
}
});
getterclass() 只是将用户的个人信息检索到其他活动中,但是当我尝试在同一活动中显示数据时,它不起作用。