我有一个水平recyclerView
,当我点击每个元素时,LinearLayout
里面有setVisibility(VISIBLE)
,这很好。
所以我现在想要的是,当我点击当前项目LinearLayout
setVisibilty(VISIBLE)
(同上)时,如果我之前点击了另一个项目,LinearLayout
里面它setVisibility(GONE)
。
到目前为止我尝试了什么
viewHolder.container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(viewHolder.linearLayout.getVisibility() == View.VISIBLE){
//hide
viewHolder.linearLayout.setVisibility(View.GONE);
}else{
int nowClickedId = 0;
//hide LinearLayout of other position that clicked before
if(nowClickedId != position){
viewHolder.linearLayout.setVisibility(View.GONE);
}
//show for current clicked item
viewHolder.linearLayout.setVisibility(View.VISIBLE);
//get current item position store at the array
nowClickedId = viewHolder.getAdapterPosition();
}
}
});
到目前为止,我只能控制当前位置的项目,如何控制之前点击的项目?
答案 0 :(得分:3)
创建一个变量来存储所单击项目的位置并将其全局声明。
Sheets("Sheet1").Protect "password", UserInterFaceOnly:= True
现在,只要点击位置,你的视图中就会将它存储到全局变量并调用private int nowclicked=-1;
,通知适配器数据已被更改。
notifyDataSetChanged()
在private class Sample extends RecyclerView.ViewHolder{
public Sample(View itemView) {
super(itemView);
viewHolder.container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nowclicked = getAdapterPosition();
notifyDataSetChanged();
}
});
}
}
中,如果位置相等,则显示onBindViewHolder
,否则将其隐藏。
linearLayout
答案 1 :(得分:1)
尝试在onBindViewHolder()方法中编写此代码并确保编写
set @up_counter = 1
set @dynamic_sql_1 = 'UPDATE '
' material_forecast_series sfs '
' JOIN material_forecast sf ON sfs.F_ID = sf.F_ID '
' JOIN material_demand sd ON sd.date_ID = sf.date_ID '
' AND sd.D_ID = sfs.D_ID '
' JOIN material_demand_series ds ON sfs.D_ID = ds.D_ID '
' JOIN OMG_membership om ON ds.item_ID = om.item_ID '
' JOIN material_FE sfe ON sfe.F_ID = sf.F_ID '
'SET sfe.v'
set @dynamic_sql_2 = CONCAT(@up_counter,' = IF(sf.v',',@up_counter,' = 0, NULL, (sd.quantity - sf.v',@up_counter,') / sf.v',@up_counter,')')
Set @dynamic_sql_2 = ' WHERE '
'sfs.forecast_ID = 15 '
' AND ds.demand_ID = 9 '
' AND ds.O_ID = 2 '
' AND om.OG_ID = 318 '
' AND sd.date_ID = 275 '
' AND sfe.date_ID = %s '
Set @final_sql = CONCAT(@dynamic_sql_1,@dynamic_sql_2,@dynamic_sql_2)
PREPARE stmt1 FROM @final_sql;
EXECUTE stmt1 ;
DEALLOCATE PREPARE stmt1;
set @up_counter = @up_counter + 1
根据职位,你可以做任何你想做的事。