バインディングは、私は変数データは、私が結合し、以下のアンドロイドのデータを使用していますAndroidのリサイクラービュー
public class DayTemp extends BaseObservable implements Serializable {
@SerializedName("dt")
long date;
@SerializedName("pressure")
double pressure;
@SerializedName("humidity")
long humidity;
@SerializedName("temp")
Temp temp;
@SerializedName("weather")
ArrayList<Weather> weathers;
@SerializedName("speed")
double speed;
@SerializedName("deg")
double deg;
@SerializedName("clouds")
double clouds;
@Bindable
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
notifyPropertyChanged(BR.date);
}
@Bindable
public double getPressure() {
return pressure;
}
public void setPressure(double pressure) {
this.pressure = pressure;
notifyPropertyChanged(BR.pressure);
}
@Bindable
public long getHumidity() {
return humidity;
}
public void setHumidity(long humidity) {
this.humidity = humidity;
notifyPropertyChanged(BR.humidity);
}
@Bindable
public Temp getTemp() {
return temp;
}
public void setTemp(Temp temp) {
this.temp = temp;
notifyPropertyChanged(BR.temp);
}
@Bindable
public ArrayList<Weather> getWeathers() {
return weathers;
}
public void setWeathers(ArrayList<Weather> weathers) {
this.weathers = weathers;
notifyPropertyChanged(BR.weathers);
}
@Bindable
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
notifyPropertyChanged(BR.speed);
}
@Bindable
public double getDeg() {
return deg;
}
public void setDeg(double deg) {
this.deg = deg;
notifyPropertyChanged(BR.deg);
}
@Bindable
public double getClouds() {
return clouds;
}
public void setClouds(double clouds) {
this.clouds = clouds;
notifyPropertyChanged(BR.clouds);
}
}
を設定するために使用していたクラスです私は天気のarraylistにアクセスすることはできませんまた、それに関連するフィールドを取得することができません。
public class Weather extends BaseObservable implements Serializable {
@SerializedName("id")
long id;
@SerializedName("main")
String main;
@SerializedName("description")
String desc;
@SerializedName("icon")
String icon;
@Bindable
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
notifyPropertyChanged(BR.id);
}
@Bindable
public String getMain() {
return main;
}
public void setMain(String main) {
this.main = main;
notifyPropertyChanged(BR.main);
}
@Bindable
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
notifyPropertyChanged(BR.desc);
}
@Bindable
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
notifyPropertyChanged(BR.icon);
}
}
レイアウトファイル:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
>
<data>
<import type="com.weatherappforleftshift.currentlocation.DateUtils"/>
<variable
name="daytemp" type="com.weatherappforleftshift.currentlocation.model.DayTemp"/>
</data>
<TextView
android:id="@+id/weather_status"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="@{HOW TO SET TEXT HERE FROM weathers list}"
android:layout_height="wrap_content" />
</layout>
私は天気クラスからの私recyclerviewにアイコンと説明を設定します。
アイテムレイアウトでこれを達成する方法
@pskink thnx –
@tynnはデータバインディングのみを要求し、クラスからarraylistにアクセスすることはできません –
_天気予報からここにテキストを設定する方法はありません。少なくとも、 'Weather'のリストを' CharSequence'に変換するコードを少なくとも提供します。ユーティリティメソッドまたは何か... – tynn