小编use*_*561的帖子

ActiveAndroid抽象类表

有谁知道是否可以在ActiveAndroid中为抽象类创建表.例如,我可以有一个抽象类Animal,它有两个具体的类Dog和Cat.我希望能够做到这样的事情:

List<Animal> animals = new Select().from(Animals.class).execute();
Run Code Online (Sandbox Code Playgroud)

这会导致'动物'包含所有已保存的猫和狗.要么:

Animal animal = new Select().from(Animals.class).where("name = ?", name).executeSingle();
Run Code Online (Sandbox Code Playgroud)

"动物"可以是猫还是狗.不幸的是,当我这样做时,我得到一个异常,因为没有为抽象类Animal创建表.有谁知道如何使用ActiveAndroid进行此操作?

java sqlite orm android activeandroid

17
推荐指数
1
解决办法
492
查看次数

房间关系匹配多个列

我之间的实体之间的关系应如下所示:

概述->有很多->类别->有很多->交易

如果Category.overviewId == Overview.id,则类别应包括在Overview中。我很确定我应该能够使用@Relation注解来实现此目标,例如:

@Relation(parentColumn = 'id', entityColumn = 'overviewId')
List<Category> categories;
Run Code Online (Sandbox Code Playgroud)

然后,我要在Category实体内包括Transaction.overviewId == Category.overviewId && Transaction.categoryId == Category.categoryId的所有事务。这是我正在努力的部分,因为@Relation批注似乎只能考虑1列。我想我想要类似的东西:

@Relation(parentColumn = {'overviewId','categoryId'}, entityColumn = {'overviewId','categoryId'})
List<Transaction> transactions;
Run Code Online (Sandbox Code Playgroud)

但这似乎不是一种有效的处理方式。有谁知道我应该如何做到这一点?我想我最终希望能够观察到一个查询,该查询将在相关的概述,类别或事务更新时更新,因此将类别和事务嵌入到概述中似乎是最好的方法,但是如果有更好的选择听到它真是太好了。

android android-room android-architecture-components

7
推荐指数
1
解决办法
282
查看次数

将 TextView 的基线与约束布局中的指南对齐

希望我在这里没有完全厚重,但我无法将 TextView 的基线与 ConstraintLayout 中的指南对齐。该指南似乎没有基线,这很烦人。有谁知道我如何实现这一目标?下面是一些不起作用的布局 xml(位于 ConstraintLayout 内):

                 <TextView
                    android:id="@+id/textToAlignBaseline"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:maxLines="1"
                    android:paddingRight="6dp"
                    android:textAppearance="@style/TextStyles.Body"
                    app:layout_constraintBaseline_toBaselineOf="@+id/guidelineBottomMargin"
                    app:layout_constraintLeft_toLeftOf="parent" />

                <Button
                    android:id="@+id/buttonToAlignBottom"
                    android:layout_width="wrap_content"
                    android:layout_height="39dp"
                    android:layout_marginRight="20dp"
                    android:background="@drawable/selector_button_bg"
                    android:paddingLeft="16dp"
                    android:paddingRight="16dp"
                    android:text="@string/clickme"
                    android:textAppearance="@style/TextStyles.Body"
                    app:layout_constraintBottom_toTopOf="@+id/guidelineBottomMargin"
                    app:layout_constraintRight_toRightOf="parent" />

                <android.support.constraint.Guideline
                    android:id="@+id/guidelineBottomMargin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    app:layout_constraintGuide_end="20dp" />
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

5
推荐指数
2
解决办法
2628
查看次数

Firebase Firestore子集合安全查询

我的Cloud Firestore数据库中有以下规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /performances/{performanceId} {
      allow read, update, delete: if request.auth.uid == resource.data.owner;
      allow create: if request.auth.uid != null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这样的想法是,您可以在拥有表演的情况下对其进行读写操作,也可以在登录后创建一个表演。

此查询工作正常:

db.collection("performances").whereEqualTo(FieldPath.of("owner"), user.getUid())
Run Code Online (Sandbox Code Playgroud)

但是,如果我想获取“场景”子集合的内容,则会收到错误消息:“ com.google.firebase.firestore.FirebaseFirestoreException:PERMISSION_DENIED:缺少权限或权限不足。” 这是以下查询:

db.collection("performances")
            .document(performanceID)
            .collection("scenes");
Run Code Online (Sandbox Code Playgroud)

我假设我需要将查询限制为如下所示,但这将不能作为whereEqualTo是查询而不是CollectionReference的输出,因此我无法访问“文档”:

db.collection("performances")
   .whereEqualTo(FieldPath.of("owner"), user.getUid())
   .document(performanceID)
   .collection("scenes");
Run Code Online (Sandbox Code Playgroud)

那么,有谁知道如果主集合具有安全规则,我应该如何访问子集合?

更新1(因为以下注释中的代码未格式化)

我想我可能想出了一个解决方案。我没有意识到我的安全规则默认情况下会拒绝从子集合中读取数据,因此将其更改为允许对表演中的场景进行所有读写都可以使其正常工作:

service cloud.firestore {
      match /databases/{database}/documents {
        match /performances/{performanceId} {
      allow read, update, delete: if request.auth.uid == resource.data.owner;
      allow create: if request.auth.uid != null;

      match /scenes/{sceneId} {
        allow read, write: if true
      }
    } …
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-firestore

2
推荐指数
1
解决办法
899
查看次数

如何使用适用于Android Studio的Google Cloud Tools侦听所有IP地址

我正在试用Android Studio的Google Cloud工具,无法从我网络上的任何其他设备访问本地服务器,也无法通过计算机的192.169.etc地址访问本地服务器.看来我需要将服务器设置为侦听所有IP地址,而不仅仅是localhost,这似乎是通过运行命令行参数--address = 0.0.0.0来完成的.问题是我根本无法在Android Studio中找到这样做的地方.有人可以帮忙吗?

google-app-engine android gradle android-studio

1
推荐指数
1
解决办法
397
查看次数