我的匕首2模块中有以下片段
@Singleton
@Provides
@ElementsIntoSet
fun providesQueries(foo: Foo): Set<Foo>{
val queries = LinkedHashSet<Foo>()
queries.add(foo)
return queries
}
Run Code Online (Sandbox Code Playgroud)
我试着以这种方式注入
@Inject lateinit var foo: Set<Foo>
Run Code Online (Sandbox Code Playgroud)
但是匕首显示一个错误,表示Dagger无法在没有@Provides或@Produces方法的情况下提供java.util.Set.
我在java中也做了同样的工作.有人知道为什么会失败吗?
我正在尝试编写一个测试来验证使用espresso启动意图,问题是目标()没有记录任何意图.
我有这个测试
@Test
public void shoulddosomething(){
startActivity();
intended(hasComponent(hasClassName(TemplatePictureCaptureActivity.class.getName())));
}
Run Code Online (Sandbox Code Playgroud)
在我的活动中我有这个代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(onRequestLayout());
Intent intent = new Intent(this, TemplatePictureCaptureActivity.class);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
测试结果是这样的.
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.
IntentMatcher: has component: has component with: class name: is "cat.helm.recertel.ui.templatepicturecapture.TemplatePictureCaptureActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String
Matched intents:[]
Recorded intents:[]
Run Code Online (Sandbox Code Playgroud)
我试图在onClickListen中启动意图并且它有效,但没有它我无法让它工作.我也尝试过闲置的资源而没有运气.你知道如何实现这个目标吗?
我在两个应用程序中有这个布局,一个在RecyclerView中,另一个在根活动布局中.
这里的布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="#CFCFCF"
android:minHeight="250dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_bright"
android:layout_above="@+id/commerceTextView"
>
<ImageView
android:src="@drawable/imagen"
android:id="@+id/commerceImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/commerceTextView"
android:gravity="center"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#F1F1F1"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"
android:paddingTop="10dp"
android:text="Best food ever"
android:paddingBottom="10dp"/>
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
适配器
public class CommercesAdapter extends RecyclerView.Adapter<CommercesAdapter.CommercesViewHolder> {
private final Context context;
private final ImageLoader loader;
private List<CommerceEntity> commercesList;
@Inject
public CommercesAdapter(Context context, ImageLoader loader) {
this.context = context; …Run Code Online (Sandbox Code Playgroud)