У меня есть это работающее приложение, которое анализирует json из API и показывает их на карточках на утилитарике. Я хочу добавить действие смахивания, чтобы удалить карты. Как и где я собираюсь добавить это действие? Я также публикую часть своих кодов ниже. Я проверил некоторые ответы на эту тему, но не смог найти, куда я их положил ...
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
item_row.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
card_view:cardCornerRadius="12dp">
<LinearLayout
android:padding="15dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="deneme"
android:gravity="left"
android:textSize="20sp"
android:id="@+id/name"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:gravity="right"
android:textSize="20sp"
android:id="@+id/city"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
RecyclerviewAdapter.java
public class RecyclerviewAdapter extends
RecyclerView.Adapter<RecyclerviewAdapter.ViewHolder> {
private Context c;
private ArrayList<itemBrewery> list;
public RecyclerviewAdapter(Context c, ArrayList<itemBrewery> list) {
this.c = c;
this.list = list;
notifyDataSetChanged();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
View v =
LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row, parent,
false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.city.setText(list.get(position).getCity());
holder.name.setText(list.get(position).getName());
}
@Override
public int getItemCount() {
return list.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView name;
TextView city;
public ViewHolder(@NonNull View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.name);
city = (TextView) itemView.findViewById(R.id.city);
}
}
}
Спасибо ...