凌晨的独白 2019-04-27 22:17
浏览 205

```为什么没有不长按没反应?想实现长按提示对话框

package com.android.dailyplanning.adapter;

import com.android.dailyplanning.R;
import com.android.dailyplanning.entity.Plan;
import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import androidx.annotation.Nullable;

public class PlanAdapter extends BaseQuickAdapter {

public PlanAdapter() {
super(R.layout.item_plan);
}
public PlanAdapter(int layoutResId, @Nullable List data) {
super(layoutResId, data);
}

@Override
protected void convert(BaseViewHolder helper, Plan item) {
helper.setText(R.id.tv_day, item.getDay());
helper.setText(R.id.tv_label, item.getLabel());
helper.setText(R.id.tv_start_time, "开始时间:"+item.getStartTime());
helper.setText(R.id.tv_end_time, "结束时间:"+item.getEndTime());
helper.setText(R.id.tv_duration, "时长:"+item.getDuration());
helper.setText(R.id.tv_keyword,"任务关键词:"+item.getKeyword());
helper.setText(R.id.tv_content, "规划内容:"+item.getContent());
helper.setText(R.id.tv_status, item.isSignIn() ? "状态:已签到" : "状态:未签到");
}
}

public class DailyFragment extends Fragment {

    @BindView(R.id.plan_list)
    RecyclerView planList;  //当价于RecyclerView planList = (RecyclerView) findViewById(R.id.plan_list)
/*    @BindView(R.id.bt_revise)
    Button btRevise;
    @BindView(R.id.bt_delete)
    Button btDelete;*/
    @BindView(R.id.btn_add_plan)
    FloatingActionButton btnAddPlan;
    Unbinder unbinder;  //
    @BindView(R.id.btn_pdf)
    FloatingActionButton btnPdf;
    private PlanAdapter planAdapter;
    private float BORDER_WIDTH = MyUtils.dip2Dimension(1, App.app);
    List<Plan> plans;
    boolean S1;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_daily, null);
unbinder = ButterKnife.bind(this, view); //注解框架ButterKnife
planList.setLayoutManager(new LinearLayoutManager(getActivity()));
planList.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
// planAdapter = new PlanAdapter();
planAdapter = new PlanAdapter(R.layout.item_plan,plans);
planList.setAdapter(planAdapter);

        //item长按删除
        planAdapter.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(BaseQuickAdapter adapter, View view, final int position) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                //    设置Title的图标
                builder.setIcon(R.drawable.ic_wc);
                //    设置Title的内容
                builder.setTitle("弹出警告框");
                //    设置Content来显示一个信息
                builder.setMessage("确定删除吗?");
                //    设置一个PositiveButton
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Plan plan1 = new Plan();
                        plan1.setObjectId(plans.get(position).getObjectId());
                        plan1.delete(new UpdateListener() {

                            @Override
                            public void done(BmobException e) {
                                if(e==null){
                                    S1 = true;
                                }else{
                                    S1 = false;
                                }
                            }
                        });
                    }
                });
                //    设置一个NegativeButton
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        return;
                    }
                });
                return S1;
            }
        });
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 luckysheet
    • ¥25 关于##爬虫##的问题,如何解决?:
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题