在我的android项目中,我正在使用mem_fn
在recyclerview中创建标题。我还通过改进下面的代码动态添加和删除项目。
代码:
public class MyadapterNew extends StatelessSection {
ArrayList<String> data;
ArrayList<String> Hdata;
public MyadapterNew(int headerResourceId, int itemResourceId,ArrayList<String>data,ArrayList<String> hdata;) {
super(headerResourceId, itemResourceId);
this.data = data;
this.Hdata=hdata;
}
class HeaderViewHolder extends RecyclerView.ViewHolder {
TextView header;
public HeaderViewHolder(View view) {
super(view);
header = (TextView)view.findViewById(R.id.header);
}
}
class MyItemViewHolder extends RecyclerView.ViewHolder {
private TextView filename;
public MyItemViewHolder(View itemView) {
super(itemView);
filename = (TextView) itemView.findViewById(R.id.filename);
}
}
public void addItem(int position, String item) {
this.data.add(position,item);
}
public void removeItem(int position) {
this.data.remove(position);
}
@Override
public RecyclerView.ViewHolder getItemViewHolder(View view) {
return new MyItemViewHolder(view);
}
@Override
public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
return new HeaderViewHolder(view);
}
@Override
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
MyItemViewHolder itemHolder = (MyItemViewHolder) holder;
itemHolder.filename.setText(data.get(position));
}
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
super.onBindHeaderViewHolder(holder);
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.Header.setText(Hdata.get(0));
}
@Override
public int getContentItemsTotal() {
return data.size();
}
}
我想要做的是,只有活动开始时才会出现所有标题,不应出现每个标题下的项目。每当用户点击标题时,该特定标题下的项目应该出现(如下拉列表)。如果用户再次单击相同的标题,则项目应消失。怎么做到这一点?