это мой код, о котором я говорил
этот код в функции onBindViewHolder
holder.tr.setOnLongClickListener(v -> {
Код: Выделить всё
int currentPosition = holder.getAbsoluteAdapterPosition();
if (currentPosition != RecyclerView.NO_POSITION) {
// تنفيذ العملية باستخدام الموضع الحالي
Cash unPaidCash = kat.get(currentPosition);
if (lastTableRowLongClick != (TableRow) v && lastTableRowLongClick != null) {
lastTableRowLongClick.setBackgroundColor(Color.parseColor("#F0F0F0"));
lastTableRowLongClick = null;
}
lastTableRowLongClick = (TableRow) v;
lastTableRowLongClick.setBackgroundColor(Color.parseColor("#2000ff00"));
PopupMenu pop = new PopupMenu(c, lastTableRowLongClick);
pop.getMenuInflater().inflate(R.menu.popupmenu, pop.getMenu());
pop.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.taf:
Users u = sql.displaySomeUser(unPaidCash.getId());
Intent profile = new Intent(c, Profile.class);
profile.putExtra("id", u.getId());
profile.putExtra("name", u.getName());
profile.putExtra("phone", u.getPhoneNumber());
profile.putExtra("box", u.getBoxNumber());
profile.putExtra("type", u.getServiceType());
profile.putExtra("current", u.getCurrent());
profile.putExtra("date", u.getDate());
c.startActivity(profile);
return true;
case R.id.daf:
AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setTitle("تأكيد الاجراء");
builder.setMessage("هل أنت متأكد ان " + unPaid.getName() + " قام بالدفع");
builder.setPositiveButton("نعم", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int number) {
sql.paidSuccess(unPaidCash.getId(), unPaidCash.getI());
kat.remove(currentPosition);
notifyItemRemoved(currentPosition);
//root.removeView(tr);
//unPaidUsers.remove(unPaid);
}
});
builder.setNegativeButton("لا", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int number) {
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
case R.id.delete:
AlertDialog.Builder builderr = new AlertDialog.Builder(c);
builderr.setTitle("تأكيد الاجراء");
builderr.setMessage(
"هل أنت متأكد انك تريد حذف " + unPaid.getName() + " من الدفع هذا الاسبوع");
builderr.setPositiveButton("نعم", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int number) {
sql.deleteUnPaidCash(unPaidCash.getId(), unPaidCash.getI());
//root.removeView(tr);
//unPaidUsers.remove(unPaid);
kat.remove(currentPosition);
notifyItemRemoved(currentPosition);
}
});
builderr.setNegativeButton("لا", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int number) {
}
});
AlertDialog alertt = builderr.create();
alertt.show();
return true;
}
return true;
}
});
pop.show();
return true;
}
return true;
});
Подробнее здесь: https://stackoverflow.com/questions/791 ... -scrolling
Мобильная версия