Я пытаюсь показать пользовательский тост точно в позиции удаленного элемента ListView.Это все, что я мог сделать:
Адаптер:
private View.OnClickListener onDeleteListener(final int position, final ViewHolder holder) {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
showCustomToast(position, position);
}
};
}
public void showCustomToast(int positionX, int positionY) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout, null, false);
ImageView icon = (ImageView) layout.findViewById(R.id.toast_image);
TextView message = (TextView) layout.findViewById(R.id.toast_text);
LinearLayout fundoMensagem = (LinearLayout) layout.findViewById(R.id.toast_root);
message.setTextColor(Color.BLACK);
fundoMensagem.setBackgroundResource(R.color.error_colors);
message.setText("Item Deleted!");
Toast toast = new Toast(context);
toast.setDuration(toast.LENGTH_LONG);
toast.setView(layout);
toast.setGravity(positionX, positionX, positionX);
toast.show();
}
Но это не совсем то, что мне нужно, потому что переменная position из onDeleteListener метод только получить индекс предмета, а не позицию на экране.Кто-то может помочь мне показать пользовательский тост в центре каждого элемента списка?