Android 检查是否已选中“回收器”视图中的项目
我想检查Android 检查是否已选中“回收器”视图中的项目,android,android-espresso,Android,Android Espresso,我想检查RecyclerView中一个项目的属性。更具体地说,我想检查是否选中了此项 首先,我选择项目 onView(withId(R.id.list_master)) .perform( RecyclerViewActions.actionOnItemAtPosition(14, clickAnItem(R.id.layout_menu)) ); 其次,检查是否选择了特定项目: onVie
RecyclerView
中一个项目的属性。更具体地说,我想检查是否选中了此项
首先,我选择项目
onView(withId(R.id.list_master))
.perform(
RecyclerViewActions.actionOnItemAtPosition(14, clickAnItem(R.id.layout_menu))
);
其次,检查是否选择了特定项目:
onView(allOf(withId(R.id.layout_menu), hasDescendant(withText("SO"))))
.check(matches(isSelected()));
使用自定义匹配器:
private static Matcher<View> isSelected() {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
return item.isSelected();
}
@Override
public void describeTo(Description description) {
description.appendText("Selected property");
}
};
检查此代码我有相同的东西想要你想要检查字段是否在回收器视图中被选中
public class AutoWithRuleListListAdapter extends RecyclerView.Adapter<AutoWithRuleListListAdapter.ViewHolder> {
private Context context;
private Fragment fragment;
private ArrayList<ObjGetLookupDataResponseIn> lookupData;
public AutoWithRuleListListAdapter(Context context, Fragment fragment, ArrayList<ObjGetLookupDataResponseIn> lookupData) {
this.context = context;
this.fragment = fragment;
this.lookupData = lookupData;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.auto_withdraw_ben_name_list, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
String output = lookupData.get(position).getDisplayName().substring(0, 1).toUpperCase() + lookupData.get(position).getDisplayName().substring(1);
holder.radioBen.setText(output);
holder.radioBen.setOnCheckedChangeListener(null);
holder.radioBen.setChecked(lookupData.get(position).isSelected());
holder.radioBen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
resetAll();
lookupData.get(position).setSelected(true);
notifyDataSetChanged();
((AutoViewRuleFragment)fragment).ruleName(position);
}
});
}
private void resetAll() {
for (int i=0;i<lookupData.size();i++)
{
lookupData.get(i).setSelected(false);
}
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return lookupData.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
RadioButton radioBen;
public ViewHolder(View itemView) {
super(itemView);
radioBen = (RadioButton) itemView.findViewById(R.id.radioReceivesFunds);
radioBen.setTypeface(Utils.gothamMedium);
}
}}
公共类AutoWithRuleListAdapter扩展了RecyclerView.Adapter{
私人语境;
私有片段;
私有ArrayList LookUpdatea;
公共AutoWithRuleListAdapter(上下文上下文、片段片段、ArrayList LookUpdatea){
this.context=上下文;
this.fragment=片段;
this.lookUpdatea=lookUpdatea;
}
@凌驾
public ViewHolder onCreateViewHolder(视图组父级,int-viewType){
View View=LayoutInflater.from(parent.getContext()).flate(R.layout.auto\u draw\u ben\u name\u list,parent,false);
返回新的ViewHolder(视图);
}
@凌驾
public void onBindViewHolder(最终视图持有人,@SuppressLint(“RecyclerView”)最终整型位置){
字符串输出=LookUpdatea.get(位置).getDisplayName().substring(0,1).toUpperCase()+LookUpdatea.get(位置).getDisplayName().substring(1);
radioBen.setText支架(输出);
holder.radioBen.setOnCheckedChangeListener(空);
holder.radioBen.setChecked(lookupdatea.get(position.isSelected());
holder.radioBen.setOnCheckedChangeListener(新的CompoundButton.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(复合按钮视图,布尔值已检查){
resetAll();
lookUpdatea.get(position).setSelected(true);
notifyDataSetChanged();
((AutoViewRuleFragment)片段).ruleName(位置);
}
});
}
私有void resetAll(){
对于(int i=0;我感谢你,但我的问题与浓缩咖啡测试有关。不幸的是,这个答案与此无关
public class AutoWithRuleListListAdapter extends RecyclerView.Adapter<AutoWithRuleListListAdapter.ViewHolder> {
private Context context;
private Fragment fragment;
private ArrayList<ObjGetLookupDataResponseIn> lookupData;
public AutoWithRuleListListAdapter(Context context, Fragment fragment, ArrayList<ObjGetLookupDataResponseIn> lookupData) {
this.context = context;
this.fragment = fragment;
this.lookupData = lookupData;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.auto_withdraw_ben_name_list, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
String output = lookupData.get(position).getDisplayName().substring(0, 1).toUpperCase() + lookupData.get(position).getDisplayName().substring(1);
holder.radioBen.setText(output);
holder.radioBen.setOnCheckedChangeListener(null);
holder.radioBen.setChecked(lookupData.get(position).isSelected());
holder.radioBen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
resetAll();
lookupData.get(position).setSelected(true);
notifyDataSetChanged();
((AutoViewRuleFragment)fragment).ruleName(position);
}
});
}
private void resetAll() {
for (int i=0;i<lookupData.size();i++)
{
lookupData.get(i).setSelected(false);
}
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return lookupData.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
RadioButton radioBen;
public ViewHolder(View itemView) {
super(itemView);
radioBen = (RadioButton) itemView.findViewById(R.id.radioReceivesFunds);
radioBen.setTypeface(Utils.gothamMedium);
}
}}