小编Sky*_*ure的帖子

如何使用android中的Room Persistance Library查询嵌套的Embeded对象?

考虑我有3个类用户,地址,位置

class Address {
    public String street;
    public String state;
    public String city;

    @ColumnInfo(name = "post_code")
    public int postCode;

    @Embedded(prefix = "home_")
    public Location homeLocation;

    @Embedded(prefix = "office_")
    public Location officeLocation;
}

class Location{
     public long lat;
     public long lng;
}

@Entity
class User {
    @PrimaryKey
    public int id;

    public String firstName;

    @Embedded(prefix = "addr_")
    public Address address;
}
Run Code Online (Sandbox Code Playgroud)

我应该如何编写查询以获得其位置在某个纬度和经度边界之间的用户?

例如:如果我想找到其所在位置在这两个点之间的所有用户Location1(13.135795,77.360348)和Location2(12.743639,77.901424).我的查询看起来像这样 -

select*from User where address.homelocation.lat <:l1_latitude && address.homelocation.lat> l2_latitude && address.homelocation.lng>:l1_longitude && address.homelocation.lng <:l2_longitude

如果我必须在我理解的嵌入位置使用前缀,请纠正我,如果错了,地址内的所有字段都将附加前缀.所以我可以查询city作为addr_city,如果我必须在homeLocation中查询lat,那么它会变成addr_home_lat吗?

嵌套对象是否允许在房间数据库中使用?如果是,那么我如何查询嵌套的嵌入对象?

这里需要一些帮助.谢谢.

sqlite android android-room android-architecture-components

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

错误:无法完成Gradle执行。原因:未知的命令行选项“ -X”

在Android Studio 1.5.1中,我收到此错误。我进行了搜索,但无法确定导致此错误的原因。

删除了所有命令行选项仍然出现错误。

检查所有xml文件是否有任何错误。仍然没有运气。

在此处输入图片说明

android android-layout android-studio android-gradle-plugin

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

当模型中的数据发生变化时,Android 数据绑定不会更新 UI

我有一个模型 CricketModel

public class CricketModel extends BaseObservable{
    private String score;
    @Bindable
    public String getScore(){
        return score
    }
    public void setScore(String s){ 
        score=s;
        notifyPropertyChanged(BR.score); 
   }
}
Run Code Online (Sandbox Code Playgroud)

当我调用 API 时,我得到 JSONArray,我将它们转换为 CricketModel 并将其添加到 CricketModel 列表中。并将此列表传递给适配器以在 Recycler 视图中显示它们。

这是我的 item_cricket.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto">

    <data>
        <variable
            name="cm"
            type="com.panasonic.arbohub.cricket.model.CricketModel" />
    </data>

    <LinearLayout xmlns:app="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:id="@+id/cv_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/dp_8"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp"
            card_view:cardCornerRadius="5dp"
            card_view:cardElevation="3dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
               <TextView
                        android:id="@+id/tv_two_s_score"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/tv_one_p_score"
                        android:layout_marginEnd="@dimen/dp_16"
                        android:layout_marginTop="@dimen/dp_8"
                        android:layout_toStartOf="@+id/rl_team_two"
                        android:textSize="@dimen/sp_12"
                        android:textStyle="bold"
                        android:text="@{cm.score}"
                        android:visibility="visible" />
            </FrameLayout>
        </android.support.v7.widget.CardView>
    </LinearLayout> …
Run Code Online (Sandbox Code Playgroud)

data-binding android android-adapter android-recyclerview android-databinding

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