1
WebViewとProgressbarの2ウェイデータバインディングを実装しようとしています。WebViewとProgressBarの2ウェイデータバインド
最初はProgressBarが引き続き表示され、webviewの読み込みが終了すると進捗バーはGONEになります。
は、しかし、私は
を結合することは、私が終了したページの読み込みをチェックするために、URLを読み込むためにWebViewのための結合アダプタを作成しても設定WebViewClientていることを作成することはできないのですが、プログレスバーの表示を更新することはできません
// ////////////ポスト
@BindingAdapter({"app:webUrl"})
public void configureWebView(WebView iWebView, String iUrl) {
iWebView.getSettings().setJavaScriptEnabled(true);
iWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// code to set visibility of progress bar
}
});
iWebView.loadUrl(iUrl);
}
////////////////////レイアウト
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<variable
name="newsUrl"
type="com.example.bindingdemo.data.model.Post" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/news_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:webUrl="@{newsUrl.url}" />
<ProgressBar
android:id="@+id/news_prog_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{**<WhatConditionToWrite>** ? View.GONE: View.Visible}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</layout>
であなたの
BindingAdapter
では、私はすべてのビューモデルを使用していません。データと簡単なデータバインディングを保持するModelクラス。それはできますか? – Napolean
@NapoleanこのモデルはViewModelです^^ –
ありがとうございます。出来た。私はちょうど変更しました hideProgressはアクセサとミューテータに従うようになります public ObservableBoolean hideProgress = new ObservableBoolean(); – Napolean