OK, ich habe endlich meine Android Data Binding Code kompilieren. Nun, es funktioniert nicht so, wie ich es erwarte. Wenn ich setCurrentShopperInfo()
von meinem Activity
anrufen, aktualisieren meine TextView
(s) nicht mit den String
s Werten, die ich einstelle.Kann nicht eine einfache TextView mit Android Data Binding
HINWEIS: Ich versuchte es auch mit ObservableField
(s), das gleiche Ergebnis.
Es HAS etwas zu sein, ich bin nicht hier zu verstehen:
LAYOUT:
<data>
<variable name="currentShopperViewModel" type="ts.kiosk.app.checkout.viewmodels.CurrentShopperViewModel" />
<import type="android.view.View" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/checkout_titlebar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_header_height"
android:layout_alignParentTop="true"
android:background="@color/header_bkgrd">
<ImageView
android:id="@+id/img_ts_logo"
android:layout_width="@dimen/app_icon_width"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/app_icon_margin"
android:layout_marginRight="@dimen/app_icon_margin"
android:src="@drawable/touchsides_logo_notext"/>
<TextView
android:id="@+id/text_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_checkout"
android:layout_toRightOf="@+id/img_ts_logo"
android:layout_centerVertical="true"
style="@style/screenTitle"/>
<LinearLayout
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_toRightOf="@+id/text_appname"
android:layout_toLeftOf="@+id/img_settings_menu"
android:paddingRight="20dip"
android:paddingLeft="20dip"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@{currentShopperViewModel.textShopperInfoName}"
style="@style/previous_transaction_titlebar"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@{currentShopperViewModel.textShopperInfoCashback}"
style="@style/previous_transaction_titlebar_cashback"
android:layout_marginLeft="20dip"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@{currentShopperViewModel.textShopperInfoPoints}"
style="@style/previous_transaction_titlebar_points"
android:layout_marginLeft="20dip"></TextView>
</LinearLayout>
ACTIVITY:
mCurentShopperViewModel = new CurrentShopperViewModel(this);
final ActivityCheckoutNewBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_checkout_new);
binding.setCurrentShopperViewModel(mCurentShopperViewModel);
VIEW MODELL:
public class CurrentShopperViewModel extends BaseObservable{
Context mCtx;
//public ObservableBoolean showShopperInfo = new ObservableBoolean();
private String textShopperInfoName;
private String textShopperInfoCashback;
private String textShopperInfoPoints;
@Bindable
public String getTextShopperInfoName() {
return this.textShopperInfoName;
}
@Bindable
public String getTextShopperInfoCashback() {
return this.textShopperInfoCashback;
}
@Bindable
public String getTextShopperInfoPoints() {
return this.textShopperInfoPoints;
}
public void setTextShopperInfoName(String name) {
this.textShopperInfoName = name;
notifyPropertyChanged(BR.textShopperInfoName);
}
public void setTextShopperInfoCashback(String cashback) {
this.textShopperInfoCashback = cashback;
notifyPropertyChanged(BR.textShopperInfoCashback);
}
public void setTextShopperInfoPoints(String points) {
this.textShopperInfoPoints = points;
notifyPropertyChanged(BR.textShopperInfoPoints);
}
public CurrentShopperViewModel(Context context) {
mCtx = context;
}
public void setCurrentShopperInfo(CardStructure cardStructure) {
//show(true);
int[] card = CardUtil.getInstance().getBalance(cardStructure);
setTextShopperInfoName(String.format("%s %s", mCtx.getResources().getString(R.string.item_wallet_desposit) , Formatter.formatCurrency(CheckoutApplication.LOCALE,card[0])));
setTextShopperInfoCashback( String.format("%s %s", mCtx.getResources().getString(R.string.item_wallet_desposit) , Formatter.formatCurrency(CheckoutApplication.LOCALE,card[0])) );
setTextShopperInfoPoints (String.format("%s %s", mCtx.getResources().getString(R.string.item_loyalty_points),card[1]));
}
Gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
android {
compileSdkVersion 20
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "ts.kiosk.app.checkout"
minSdkVersion 16
targetSdkVersion 16
versionCode 2
versionName "0.0.2.258"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
dataBinding{
enabled = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:20.0.0'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'net.danlew:android.joda:2.7.2'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
//compile 'com.squareup.okhttp:okhttp:2.0.0'
// Robolectric
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' // fixes issue on linux/mac
testCompile 'org.robolectric:robolectric:3.0'
compile project(':asterixmodule')
compile project(':servicemodule')
compile project(':sdfclient')
}
android {
packagingOptions {
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties'
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
}
}
Logcat:
nicht sicher, was, was hier von Bedeutung sein würde, aber ich sehe das, nachdem ich setCurrentShopperInfo()
von meinem Activity
nennen:
04-12 21:31:30.252 866-866/ts.kiosk.app.checkout E/java.lang.StackTraceElement: InterfaceError
PROPERTY NOTIFY GEÄNDERT Debugging
Ich trat in die notifyPropertyChanged() Methode und mCallbacks Größe ist 0 --- ist das korrekt?
/**
* Notifies listeners that a specific property has changed. The getter for the property
* that changes should be marked with {@link Bindable} to generate a field in
* <code>BR</code> to be used as <code>fieldId</code>.
*
* @param fieldId The generated BR id for the Bindable field.
*/
public void notifyPropertyChanged(int fieldId) {
if (mCallbacks != null) {
mCallbacks.notifyCallbacks(this, fieldId, null);
}
}
Ich habe auch versucht die ObservableField Art und Weise der Einstellungsdaten verbindlich, wenn letztlich das nennt man:
public synchronized void notifyChange() {
if (mCallbacks != null) {
mCallbacks.notifyCallbacks(this, 0, null);
}
}
und mCallbacks ist wieder null und ich denke, dass ist ein Thema, aber nicht wissen, wie um es zu debuggen.
Könnte sein wert, einschließlich Gradle Konfiguration auch. – stkent
Bitte melden Sie Ihre Log-Katze – Jois
hat jemand irgendwelche Hinweise? Gibt es eine Möglichkeit, dies zu debuggen? – Mike6679