Там в деятельность простирается RoboFragmentActivity, это главное пользовательский интерфейс является ViewPager содержать 3 фрагмента, XML ниже:обновление активности ImageView из фрагмента WebView Javascript
<android.support.v4.view.ViewPager
android:id="@+id/goods_details_vp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1.0"
android:background="@color/white"
android:flipInterval="30"
android:persistentDrawingCache="animation" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:background="#cc000000"
android:orientation="horizontal"
android:paddingLeft="10dp" >
<RelativeLayout
android:id="@+id/collection_view_lay"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:layout_weight="2" >
<ImageView
android:id="@+id/collection_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/icon_goods_detials_collct_common" />
</RelativeLayout>
</LinearLayout>
каждый фрагмент имеет WebView, XML ниже:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/goods_details"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</WebView>
WebView в 1-й фрагмент будет вызывать метод так:
class InJavaScript {
@JavascriptInterface
public void runOnAndroidJavaScript(String status) {
collectionStatus.setCollectionStatus(status);
}
}
метод обратного вызова в деятельности:
@Override
public void setCollectionStatus(String str) {
// TODO 设置收藏图标
if ("true".equals(str)) {
collectionView
.setImageResource(R.drawable.icon_goods_detials_collct_pressed);
} else {
collectionView
.setImageResource(R.drawable.icon_goods_detials_collct_common);
}
}
Теперь вопрос является, если я позволю CollectionView в setImageResource, фрагменты будут все disappeared.The метод уже побежал, я могу даже получить ул выше как " правда».if изменить код выше как:
@Override
public void setCollectionStatus(String str) {
Log.e("tag", str);
}
бревно проходит perfectly.I запутался с этой проблемой, надеюсь, вы можете помочь me.thanks много.