我按照这些来创建可检查的组合框
http://programmingexamples.net/wiki/Qt/ModelView/ComboBoxOfCheckBoxes
然而,当我执行此操作 - > Model-> clear()然后添加项目时,组合框文本(用户单击任何内容之前显示的文本组合框)变为空白。单击组合框时,项目仍将显示并可检查。我怀疑clear()删除标题并导致这个,但我尝试setHorizontalHeaderLabels等但我仍然无法设置组合框文本。我错过了什么?
答案 0 :(得分:1)
添加项目后,尝试设置ComboBox的选定索引。像:
public class StraggredView extends RecyclerView.Adapter<StraggredView.ViewHolder> {
private List<Content> mDataSet;
private Context ctx;
public StraggredView(Context context, List<Content> arrList) {
ctx = context;
mDataSet = arrList;
}
@Override
public StraggredView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_grid, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
if(getItemCount()==position)
{
//// I AM NOT GETTING IT AT THE BOTTOM... IT INVOKED AS THE ADAPTER IS CALLED FIRST TIME...LOOK AT IT
}
if (mDataSet.get(position).getContentImage() == null || mDataSet.get(position).getContentImage().isEmpty()) {
Glide.with(ctx).load(R.drawable.no_content)
// .override(screenWidth / 2, Utils.dpToPx(height))
.into(holder.imgContent);
} else {
Glide.with(ctx).load(mDataSet.get(position).getContentImage())
// .override(screenWidth / 2, Utils.dpToPx(height))
// .centerCrop()
//.transform(new CircleTransform())
.into(holder.imgContent);
}
holder.imgContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDataSet.get(position).getContentImage() != null
|| !mDataSet.get(position).getContentImage().isEmpty()) {
FragmentActivity activity = (FragmentActivity) (ctx);
FragmentManager fm = activity.getSupportFragmentManager();
FullScreenFragment dialog = FullScreenFragment.newInstance(
mDataSet.get(position).getContentImage());
dialog.show(fm, "dialog");
}
}
});
}
@Override
public int getItemCount() {
return this.mDataSet.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView imgContent;
public ViewHolder(View itemView) {
super(itemView);
imgContent = (ImageView) itemView.findViewById(R.id.imgContent);
}
}
}
因为清除ComboBox后可能会出现这样的情况,即使添加项目,它的显示索引也可能会变为-1并保持不变。