content: package cn.amamiya.hupublacklist.adapter;
  
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.SharedPreferences;
  import android.view.HapticFeedbackConstants;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  import java.io.File;
  import java.util.List;
  
  import cn.amamiya.hupublacklist.utils.FileHelper;
  
  public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> {
  
      private Context context;
      private List<String> dataList;
  
      private File file;
  
      public MyRecyclerViewAdapter(Context context, List<String> dataList, File file) {
          this.context = context;
          this.dataList = dataList;
          this.file = file;
      }
  
      @NonNull
      @Override
      public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, parent, false);
          return new ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
          String item = dataList.get(position);
          holder.textView.setText(item);
          int currentPosition = holder.getAdapterPosition(); // 获取当前位置
          holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  AlertDialog.Builder builder = new AlertDialog.Builder(context);
                  builder.setTitle("移除黑名单");
                  builder.setMessage("是否将「"+item+"」移出黑名单");
                  builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          // 在这里执行删除操作
                          dataList.remove(currentPosition);
                          notifyDataSetChanged();
                          String blackList = String.join(",",dataList);
                          FileHelper.modifyFileContent(file,blackList);
                      }
                  });
                  builder.setNegativeButton("否", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          dialog.dismiss();
                      }
                  });
                  builder.show();
  
                  return true;
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return dataList.size();
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
          TextView textView;
  
          public ViewHolder(View itemView) {
              super(itemView);
              textView = itemView.findViewById(android.R.id.text1);
          }
      }
  }
  