• 团队冲刺第六天-KeepRunningAPP


    摘要:今天完成了闹钟的添加功能,过程还算顺利,但是在最后实现长按删除闹钟事件的使用遇到了问题,无法实现长按删除,由于在闹钟列表里使用了Switch开关控件,所以我感觉和这个有关系,于是拿掉了Switch控件测试了一下,果然实现了长按删除,具体什么原因还不清楚,打算明天解决,然后再美化一下界面啥的,然后学习闹钟的触发事件。

    package com.example.naozhong;
    
    import android.app.TimePickerDialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.TimePicker;
    import android.widget.Toast;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import java.util.Calendar;
    
    public class AddAlarm extends AppCompatActivity implements View.OnClickListener {
        private TextView hour;
        private TextView minute1;
        private Button setTime;
        private EditText content;
        private Button save;
        private Calendar calendar;
        private AlarmOperator alarmOperator;
        private AlarmAdapter alarmAdapter;
        String hourformat;
        String minuteformat;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.addalarm);
            alarmOperator=new AlarmOperator(this);
            hour = findViewById(R.id.hour);
            minute1 = findViewById(R.id.minute);
            setTime = findViewById(R.id.set_time);
            setTime.setOnClickListener(this);
            content = findViewById(R.id.content);
            save = findViewById(R.id.save);
            save.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.set_time:
                    addtime();
                    break;
                case R.id.save:
                    addalarm();
                    break;
    
            }
        }
    
        private void addalarm() {
            String userhour=hour.getText().toString().trim();
            String userminute=minute1.getText().toString().trim();
            String usercontent=content.getText().toString().trim();
            Alarm bean=new Alarm("2",userhour,userminute,usercontent,0);
            Log.d("volley", bean.hour);
            alarmOperator.insert(bean);
            Intent intent2 = new Intent(this, AlarmActivity.class);
            startActivity(intent2);
    
        }
    
        private void addtime() {
            calendar = Calendar.getInstance();
            int mhour = calendar.get(Calendar.HOUR_OF_DAY);
            int mminute = calendar.get(Calendar.MINUTE);
            new TimePickerDialog(AddAlarm.this, new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    
                    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    calendar.set(Calendar.MINUTE, minute);
                    Calendar currentTime=Calendar.getInstance();
                    if(calendar.getTimeInMillis()<=currentTime.getTimeInMillis()){
                        calendar.setTimeInMillis(calendar.getTimeInMillis()+24*60*60*1000);
                    }
                    hourformat = String.format(String.valueOf(hourOfDay));
                    minuteformat = String.format(String.valueOf(minute));
                    Toast.makeText(AddAlarm.this, "" + hourformat + ":" + minuteformat, Toast.LENGTH_SHORT).show();
                    hour.setText(hourformat);
                    minute1.setText(minuteformat);
    
                }
            }, mhour, mminute, true).show();
        }
    }
    AddAlarm
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.alarm);
            addalarm=findViewById(R.id.addalarm);
            list=new ArrayList<>();
            String username="2";
            alarmOperator =new AlarmOperator(this);
            ListView alarmList=(ListView) findViewById(R.id.clock_list);
            alarmList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
                    AlertDialog.Builder builder=new AlertDialog.Builder(view.getContext());
                    builder.setMessage("确定删除?");
                    builder.setTitle("提示");
                    final Alarm[] alarms = {null};
                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            alarms[0]=list.get(position);
                            alarmOperator.deletebyuser("1",alarms[0].hour,alarms[0].minute);
                            list.remove(position);
                            alarmAdapter.notifyDataSetChanged();
                        }
                    });
                    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
    
                        }
                    });
                    builder.create().show();
                    return false;
                }
            });
            init(username);
            alarmAdapter=new AlarmAdapter(this,list);
            alarmList.setAdapter(alarmAdapter);
            addalarm.setOnClickListener(l);
        }
    Alarm

  • 相关阅读:
    JavaScript设计模式样例八 —— 适配器模式
    JavaScript设计模式样例七 —— 原型模式
    JavaScript设计模式样例六 —— 抽象工厂模式
    JavaScript设计模式样例五 —— 建造者模式
    JS比较两个时间的时间差
    使用nginx实现纯前端跨越
    npm的使用总结
    优雅的格式化时间显示
    优雅的封装ajax,含跨域
    将自己的域名代理到Gitpages
  • 原文地址:https://www.cnblogs.com/MoooJL/p/12741005.html
Copyright © 2020-2023  润新知