Home > Mobile >  Android litepal database table when a foreign key is empty
Android litepal database table when a foreign key is empty

Time:09-18

Recently learned that when learning android USES a database litepal
Just made a small demo
Need to establish a relationship is
Users - the task 1: n
Users - goods 1: n
Data reference is Guo Lin teacher blog
https://blog.csdn.net/guolin_blog/article/details/39207945

When the task is to create a good after see foreign key is associated with good database and even up to the user id caption

Goods there also created the same to see foreign key database is associated with good caption

Data can be found at this time the task of the interface disappeared view to the database later found to be a foreign key is empty caption

So, every brother please help solve this problem, thank you!

Duty Duty=new Duty ();
Duty. SetTime (simpleDateFormat. The format (date));
Duty. SetHead (duty_head);
Duty. SetPriority (priority);
If (duty_category. Equals (" daily task ")) {
Duty. SetCategory (1);
The d (TAG, "onClick: classification to the daily task");
} else if (duty_category equals (" weekly tasks ")) {
Duty. SetCategory (2);
The d (TAG, "onClick: classification to the weekly tasks");
} else if (duty_category equals (" monthly tasks ")) {
Duty. SetCategory (3);
The d (TAG, "onClick: classification to the monthly task");
}
If ((TextUtils isEmpty (duty_head))) {
Toast. MakeText (DutyCreate. This, "what kind of goal, there will be what kind of life", Toast. LENGTH_SHORT), show ();
}


If ((TextUtils isEmpty (duty_achp))) {
Toast. MakeText (DutyCreate. This, "everything has the value of existence", Toast. LENGTH_SHORT), show ();
} else {
If (isNumeric (duty_achp)) {

SharedPreferences preferences=getSharedPreferences (" data ", MODE_PRIVATE);
String currentUser=preferences. Get String (" currentUser ", "null");
Int currentUser_id=preferences. Get int (" currentUser_id ", 0).

Duty. SetAchp (Integer. ParseInt (duty_achp));
Duty. SetOver (false);
//duty. SetUser (currentUser);
Duty. The save ();

The List & lt; User> CUser=LitePal. Where (" account=?" , currentUser). Find (User. The class);
For (User cuser: cuser)
{
Cuser. GetDutyList (). The add (duty);
Cuser. The save ();
}




Shop Shop=new Shop ();

Shop. SetShop_name (shophead);
/* shop. SetShop_pay (Integer. ParseInt (pay)); */
Shop. SetLove (love);

{if (TextUtils. IsEmpty (shophead))
Toast. MakeText (ShopCreate. This, "what kind of goal, there will be what kind of life", Toast. LENGTH_SHORT), show ();

} else {

If ((TextUtils isEmpty (pay))) {
Toast. MakeText (ShopCreate. This, "everything has the value of existence", Toast. LENGTH_SHORT), show ();
} else {
If (isNumeric (pay)) {
Shop. SetShop_pay (Integer. ParseInt (pay));
Shop. SetOver (false);
Shop. The save ();
SharedPreferences preferences=getSharedPreferences (" data ", MODE_PRIVATE);
String currentUser=preferences. Get String (" currentUser ", "null");

List CUser=LitePal. Where (" account=?" , currentUser). Find (User. The class);
For (User cuser: cuser)
{
Cuser. GetShopList (). The add (shop);
If (cuser. The save ())
{
The d (TAG, "onClick: save successfully!!!!!!!!!!!!!!!!!!!!! ");
}

}
  • Related