gpt4 book ai didi

java - 底部片材回收器 View 支架

转载 作者:行者123 更新时间:2023-12-02 13:34:33 26 4
gpt4 key购买 nike

我有一个 recyclerview,它获取数据作为领域结果,然后将其显示为 recyclerview 项目。我的想法是,当用户单击某个项目时,会弹出一个底页并显示详细信息。

有没有一种方法可以在 onBindViewHolder 中将数据传递到bottomsheet,然后在 onClick 方法中显示bottomsheet?谢谢

这是我的代码

public class EmployeeRVAdapterTable extends RecyclerView.Adapter<EmployeeRVAdapterTable.EmployeeViewHolderTable> implements RealmChangeListener {
private RealmResults<Predavanja> mEmployees;


public EmployeeRVAdapterTable(RealmResults<Predavanja> employee) {
this.mEmployees = employee;
mEmployees.addChangeListener(this);
}

@Override
public EmployeeViewHolderTable onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.table_row_item, parent, false);
return new EmployeeViewHolderTable(view);
}

@Override
public void onBindViewHolder(EmployeeViewHolderTable holder, int position) {

Predavanja predavanja = mEmployees.get(position);
holder.tablename.setText(predavanja.getPredmetPredavanja());
holder.tabletype.setText(predavanja.getRasponVremena());
holder.tablemjesto.setText(predavanja.getDvorana());


switch (predavanja.getPredavanjeIme()){
case("Predavanja,"):
holder.tableboja.setBackgroundResource(R.color.blue_nice);
break;
case("Auditorne vježbe,"):
holder.tableboja.setBackgroundResource(R.color.green_nice);
break;
case("Kolokviji,"):
holder.tableboja.setBackgroundResource(R.color.purple_nice);
break;
case("Laboratorijske vježbe,"):
holder.tableboja.setBackgroundResource(R.color.red_nice);
break;
case("Konstrukcijske vježbe,"):
holder.tableboja.setBackgroundResource(R.color.grey_nice);
break;
case("Seminar,"):
holder.tableboja.setBackgroundResource(R.color.blue_nice);
break;
case("Ispiti,"):
holder.tableboja.setBackgroundResource(R.color.purple_dark);
break;
}


}

@Override
public int getItemCount() {
return mEmployees.size();
}

public class EmployeeViewHolderTable extends RecyclerView.ViewHolder implements View.OnClickListener{
TextView tablename, tabletype, tablemjesto;
RelativeLayout tableboja;


public EmployeeViewHolderTable(View itemView) {
super(itemView);
tablename = (TextView) itemView.findViewById(R.id.table_name);
tabletype = (TextView) itemView.findViewById(R.id.table_type);
tableboja = (RelativeLayout)itemView.findViewById(R.id.colorMe);
tablemjesto = (TextView)itemView.findViewById(R.id.table_mjesto);
itemView.setOnClickListener(this);
}

@Override
public void onClick(View view) {
Context context = view.getContext();


TextView info, info2,info3;


final BottomSheetDialog dialog;
View views = LayoutInflater.from(context).inflate(R.layout.bottom_sheep, null);

info = (TextView) views.findViewById(R.id.predavanjeImeDialog);


dialog = new BottomSheetDialog(context);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(views);
dialog.show();
}
}


@Override
public void onChange(Object element) {
notifyDataSetChanged();
}
}

最佳答案

最好的方法是获取项目的位置,然后在集合中获取该项目并使用您想要的数据。

@Override
public void onClick(View v) {
int position= getAdapterPosition();
String detail= mEmployees.get(position).getDetail();
// Do what you want with the detail
}

关于java - 底部片材回收器 View 支架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com