要包含的布局是这样的,child.xml:
<layout>
<data>
<variable
name="click"
type=""> <!-- What type should be here? -->
</data>
<LinearLayout>
<View onClick="@{click}"/>
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
要包含此内容,parent.xml:
<layout>
<data>
<variable
name="viewModel"
type="ViewModel"/>
</data>
<LinearLayout>
<View onClick="()->viewModel.click1()"/>
<include
bind:click="()->viewModel.click2()"/>
layout="@layout/child"/>
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
那么如何将 clickEvent 仅传递给 child.xml。由于不同的 parent.xml 具有不同的 ViewModel,我认为我不应该将 viewModel 传递给 child.xml。但我不知道如何将方法传递给 child.xml。
我现在正在做的解决方案是 Java 文件中的 setOnClickListener。我怀疑 dataBinding 是否可以使它更容易。
当我替换一个片段时,它会被破坏。我尝试在活动的 onCreate 中创建片段并将其引用保留在活动中,并在我“重新显示”或“重新打开”它时通过调用替换引用来使用它,但这并没有帮助,片段被销毁(替换时)由另一个片段)并重新创建。解决办法应该是什么?
我想要实现的是说WhatsApp,其中不可见时不应销毁片段,除非我没有使用滑动手势而是使用常规按钮。
谢谢。
android android-fragments fragmenttransaction fragmentmanager
毕加索不是onBitmapLoaded第一次打电话,如果你知道,请告诉我
txtView = (TextView) centerRelative.getChildAt(i);
Picasso.with(getBaseContext()).load(file[i-4]).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
txtView.setBackground(new BitmapDrawable(getResources(),bitmap));
// Not executing for the first time
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// executing for the first time
}
});
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
txtView.setBackground(new BitmapDrawable(getResources(),bitmap));
logd("onBitmapLoaded");
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) { …Run Code Online (Sandbox Code Playgroud) 为什么我们扩展应用程序类。Android应用即使没有扩展也能正常运行。
任何人都可以将这种情况解释为我们到底为什么要对其进行扩展。
例如:
public class MyApp extends Application {
private static MyApp app;
private ImageDownloaderComponent imageDownloaderComponent;
@Override
public void onCreate() {
super.onCreate();
app = this;
imageDownloaderComponent = DaggerImageDownloaderComponent.builder().imageDownloaderModule(new ImageDownloaderModule(this)).build();
}
}
Run Code Online (Sandbox Code Playgroud)