凌晨的独白 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 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog