我的TabLayout包含3个片段。我还在每个菜单中都有徽章视图,然后在片段2和3中,当添加新数据时,我增加了徽章视图。一切顺利但是我不知道如何在单击新项目时减少。我尝试了这段代码,但仍然对我不起作用
在我的两个片段中,添加数据后徽章会增加。
View b= ((MainActivity)view.getContext()).tabTwo;
BadgeView badge3 = new BadgeView(view.getContext(), b);
badge3.setBadgeMargin(90,0);
badge3.setTextSize(10);
badge3.setText(""+(-1));
badge3.show();
这是适配器,我的实现是当用户单击新数据时。 badgeview将减少1。
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
final DaftarTugas tugas = listTugas.get(position);
holder.nama_matkul.setText(tugas.getNama_tugas());
holder.judul_tugas.setText(tugas.getJudul_tugas());
holder.tanggal_tugas.setText(tugas.getTanggal_tugas());
Log.e("tugansya","1");
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), PengumumanTugasDetail.class);
DatabaseReference flag_tugas = FirebaseDatabase.getInstance().getReference("flag_tugas");
row_index=position;
View b= ((MainActivity)view.getContext()).tabTwo;
BadgeView badge3 = new BadgeView(view.getContext(), b);
badge3.setBadgeMargin(90,0);
badge3.setTextSize(10);
badge3.setText(""+(-1));
badge3.show();
//still error here
flag_tugas.child(tugas.getIdCourse()).child(tugas.getIdTugas()).child(users.getUid()).setValue("o");
intent.putExtra("flag", "tugas");
intent.putExtra("namamatkultugas", tugas.getNama_tugas());
intent.putExtra("deskripsitugas", tugas.getDeskripsi_tugas());
intent.putExtra("judultugas", tugas.getJudul_tugas());
intent.putExtra("tanggalkumpul", tugas.getTanggal_kumpul());
intent.putExtra("tanggaltugas", tugas.getTanggal_tugas());
notifyDataSetChanged();
view.getContext().startActivity(intent);
}
});
if(tugas.getFlag() != null) {
if (tugas.getFlag().equals("a")) {
Log.e("mantul", " masuk a");
holder.itemView.setBackgroundColor(Color.parseColor("#e3f2fd"));
holder.notif_tugas.setVisibility(View.VISIBLE);
} else {
Log.e("mantul", " masuk o");
holder.itemView.setBackgroundColor(Color.parseColor("#ffffff"));
holder.notif_tugas.setVisibility(View.GONE);
}
}else {
}
在此用例中如何实现接口?或其他解决方案