在Android上工作时,ORMLite是否只保存浅层对象?我有一个嵌套对象的数据结构,这两个对象都是新创建的,我希望能够通过一次调用dao.create()来保存它们.
例如,我有以下父类.
@DatabaseTable
public class Parent {
@DatabaseField(generatedId=true)
public int id;
@DatabaseField
public String name;
@DatabaseField
public Child child;
}
Run Code Online (Sandbox Code Playgroud)
和以下儿童班.
@DatabaseTable
public class Child {
@DatabaseField(generatedId=true)
public int id;
@DatabaseField
public String name;
}
Run Code Online (Sandbox Code Playgroud)
我希望能够做到以下几点.
Parent parent = new Parent();
parent.name = "ParentName";
Child child = new Child();
child.name = "ChildName";
parent.child = child;
// .. get helper and create dao object...
dao.create(parent);
Run Code Online (Sandbox Code Playgroud)
执行此操作时,父对象是持久的但不是子对象,并且child_id父表中的自动生成列设置为0.这是正常行为吗?有没有办法让嵌套对象保持不变并传播主键?
我有一个多行文本视图设置为android:layout_width="wrap_content",当渲染时,获取父的所有可用宽度.当文本可以放在一行上时,wrap_content工作正常,但在两行或多行时,文本视图似乎与父项宽度匹配,在两侧留下看起来像填充的内容.
因为文本不能放在一行上,文本视图是否需要所有可用的宽度?我希望视图受最小可能尺寸的限制.
有任何想法吗?
作为参考,这里是布局定义:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:singleLine="false"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/white"
android:gravity="center_horizontal"
/>
Run Code Online (Sandbox Code Playgroud) 我有一个在后台下载文件的持续通知.我已经成功创建了多个同时更新进度条通知,这些通知也可以取消.这适用于所有经过测试的设备,除了一些最近使用Honeycomb的Android平板电脑.
现在的效果是原始通知消息不断被重新显示,从而阻止用户点击时钟以显示正在进行的通知列表.因此,甚至没有看到进度条.有没有人成功地在Honeycomb上创建进度条通知?
作为一方,我还发现我的黑色通知文本不再具有通知列表的黑色背景.有没有办法为Honeycomb设备设置白色文本?
注意:这已经在运行Android 3.0.1和Motorola Xoom的Optimus Pad L-06C上进行了测试
以下是通知创建
// Create new notification for downloading
mNotification = new Notification(R.drawable.owl_icon, getNotificationText(R.string.notification_content_downloading), 0);
mNotification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT);
// Create custom progress bar view
RemoteViews contentView = new RemoteViews(CourseSyncService.this.getPackageName(), R.layout.notification_downloading);
contentView.setTextViewText(R.id.notificationTitle, mCourseTitle);
contentView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
contentView.setTextViewText(R.id.notificationPercentage, "0%");
mNotification.contentView = contentView;
// Create pending intent for the notification
Intent notificationIntent = new Intent(CourseSyncService.this, CancelDownloadActivity.class);
notificationIntent.putExtra(CourseSyncService.KEY_USER_ID, mUserId);
notificationIntent.putExtra(CourseSyncService.KEY_COURSE_ID, mCourseId);
notificationIntent.putExtra(CourseSyncService.KEY_COURSE_TITLE, mCourseTitle);
PendingIntent contentIntent = PendingIntent.getActivity(CourseSyncService.this, mCourseId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
mNotification.contentIntent = contentIntent;
// …Run Code Online (Sandbox Code Playgroud)