今日帮前同事擦屁股,遇见了一个奇怪的问题,他在一个PopupWindow中嵌套了RecycleView和一个GridView实现了类似于fragment切换的效果,如图,
3条回答
- qq_18232369 2018-12-05 07:00关注
上面的散热器、壁挂炉之类的是写在RecycleView中的,下面的选项写在GridView中,给recycleview的item设置点击事件,改变下方GridView里的内容。那么问题来了,点击recycleview里的item时,GridView里的item加载的时候会导致上方区域变成透明的,opupwindow覆盖的内容会显视出来感觉很奇怪,因为每次加载的item数量是不一致的,出现了这么一个问题,item多的加载少的,不会变透明,少的加载多的就会变透明。然后透明的时候点一下GridView就又正常了,或者在跳出输入法的情况下切换就没有问题,想不明白白这是为什么?点击事件代码如下:
public void onItemClick(View view, int position) {
classPostipon=position;
// 实现单选 利用遍及循环
for (ProductListBean.TypelsBean.ZiBeanX bean : ziBeanXListi) {//全部设为未选中
bean.setSelect(false);
}
ziBeanXListi.get(position).setSelect(true);
productClassPopuListAdapter.notifyDataSetChanged();
ziBeanList.clear();
ziBeanList.addAll(ziBeanXListi.get(position).getZi());
if (ziBeanList!=null){
// 加载两级列表下侧数据
// productClassRightPopuListAdapter=
// new ProductClassRightPopuListAdapter(ProductListActivity.this,ziBeanList);
// productGridView.setAdapter(productClassRightPopuListAdapter);
//productClassRightPopuListAdapter.notifyDataSetChanged();
for (ProductListBean.TypelsBean.ZiBeanX.ZiBean bean : ziBeanList) {//全部设为未选中
bean.setIsselect(false);
}
// 然后通过选择的id与数据id比较 进行用户选中效果
for (int i=0;i<ziBeanList.size();i++){
String classID=ziBeanList.get(i).getId();
if (classID.equals(catid)){
ziBeanList.get(i).setIsselect(true);
}else {
ziBeanList.get(i).setIsselect(false);
}
}
}
productClassRightPopuListAdapter.notifyDataSetChanged();
productGridView.smoothScrollToPosition(ziBeanList.size()-1);
}
});
对应的adapter代码:
public View getView(int arg0, View arg1, ViewGroup arg2) {
ViewHolder holder = null;
if (arg1 == null) {
holder = new ViewHolder();
arg1 = View.inflate(context, R.layout.product_class_popu_item ,null);
holder.tv_name = (TextView) arg1.findViewById(R.id.product_class_tv);
arg1.setTag(holder);
} else {
holder = (ViewHolder) arg1.getTag();
}
if (list.get(arg0).isSelect()==true){
holder.tv_name.setTextColor(Color.parseColor("#FFFFFF"));
holder.tv_name.setBackgroundColor(Color.parseColor("#2BA0FF"));
}else {
holder.tv_name.setTextColor(Color.parseColor("#666666"));
holder.tv_name.setBackgroundColor(Color.parseColor("#EEEEEE"));
}
holder.tv_name.setText(list.get(arg0).getName());
return arg1;
}
static class ViewHolder {
private TextView tv_name;
}
求大神帮帮我!解决 无用评论 打赏 举报