首页 > 其他分享 >2.13

2.13

时间:2024-02-28 15:13:07浏览次数:29  
标签:private cursor clist new import android 2.13

package com.example.myapplication;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ListAdapter listAdapter;
    private String month11;
    private DBHelper helper;
    private  ListView listView;
    private List<costList>list;
    private TextView textView;
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent = getIntent();
        month11 = intent.getStringExtra("date");
        initView();
        initData();
      listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
              new AlertDialog.Builder(MainActivity.this).setTitle("注意")
                      .setMessage("是否删除要此项记录?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                      String view1= String.valueOf(listAdapter.getItemId(position));
                      SQLiteDatabase db = helper.getWritableDatabase();
                      db.delete("account2","_id= ?",new String[]{view1});
                      Toast.makeText(getBaseContext(), "已删除", Toast.LENGTH_SHORT).show();
                      initData();
                  }
              }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int whichButton) {
                              Toast.makeText(getBaseContext(), "已取消删除", Toast.LENGTH_SHORT).show();
                          }
                      }).create().show();
              return false;
          }
      });
    }

    @SuppressLint("Range")
    private void initData() {
        list=new ArrayList<>();
        SQLiteDatabase db=helper.getReadableDatabase();
        Cursor cursor=db.query("account2",null,"Date like '"+month11+"%'",null,null,
                null,null);
        BigDecimal sum=new BigDecimal(0);
        while (cursor.moveToNext()){
            costList clist=new costList();//构造实例
            BigDecimal temp=new BigDecimal(cursor.getString(cursor.getColumnIndex("Money")));
            sum=sum.add(temp);
            clist.setSe(cursor.getString(cursor.getColumnIndex("Se")));
            clist.set_id(cursor.getString(cursor.getColumnIndex("_id")));
            clist.setTitle(cursor.getString(cursor.getColumnIndex("Title")));
            clist.setDate(cursor.getString(cursor.getColumnIndex("Date")));
            clist.setMoney(temp.toString());
            list.add(clist);
        }
        //绑定适配器
        listAdapter=new ListAdapter(this,list);
        listView.setAdapter(listAdapter);
        textView.setText(sum.toString());
        db.close();
    }
    private void initView() {
        helper=new DBHelper(MainActivity.this);
        listView = findViewById(R.id.list_view);
        textView =findViewById(R.id.t_money);
    }
}

标签:private,cursor,clist,new,import,android,2.13
From: https://www.cnblogs.com/luoqingci/p/18040466

相关文章

  • 2.13 密码的修改
    密码的修改<%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head><title>新密码</title></head><body><divstyle="text-align:center"><formaction="......
  • 2.13
    今天学vue的组件化开发,组件的局部注册和全局注册现在写页面就可以像拼图一样,将一个个组件拼起来了,方便快捷了不少.今日代码<template><divclass="hm-Footer">芝士Footer<hm-button>按钮</hm-button></div></template><script>importHmButton......
  • 2024.2.13 LGJ Round
    A一个圆上有\(2n\)个点,你需要选出\(n\)个点对连一条线段,其中一些点对已经被选。问所有点对方案中,联通块个数的和,联通的含义是线段相交,那么两条线段的端点都互相可达。\(n\le300\)。线段相交,把圆放到序列上就是区间相交然而不包含。我们拆贡献,计算每个区间\([l,r]\)的......
  • 闲话2.13
    哎嘿,我复活了!昨天到的西安,旅游体验很棒啊......
  • 2.13
           ......
  • 【ubantu22.10】安装部署timescaledbv2.13.0及postgresql v14.10
    一、安装部署postgresql-timescaledbaptinstallgnupgpostgresql-commonapt-transport-httpslsb-releasewget二、运行postgresql存储库设置脚本/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh三、添加timescaledb第三方存储库echo"debhttps://packageclo......
  • 12.13
    《程序员修炼之道》第七章在项目开始之前的阅读笔记这一章讨论了在项目开始之前要面临的一些问题和挑战,以及如何应对和解决它们。作者提出了以下几个主题:不要搜集需求,而要挖掘需求。需求是用户想要解决的问题,而不是用户目前做事情的方式。要站在用户的角度,了解他们的真正需求和......
  • 12.13
    UserMapperpackagecom.example.mapper;importcom.example.pojo.Agent;importcom.example.pojo.Customer;importcom.example.pojo.House;importcom.example.pojo.Users;importorg.apache.ibatis.annotations.*;importjava.util.List;@Mapperpublicinterf......
  • 12.13
    UserMapperpackagecom.example.mapper;importcom.example.pojo.Agent;importcom.example.pojo.Customer;importcom.example.pojo.House;importcom.example.pojo.Users;importorg.apache.ibatis.annotations.*;importjava.util.List;@Mapperpublicinterfa......
  • 12.13日
    早上五点多一点就醒来了,在床上坐着,闭目,再睁眼就是六点了。舍友们都还在睡梦,我静静穿好衣服,拿好洗漱用品,洗漱完简单收拾了一下,拿上早上上课用的书笔就离开了。一晚上的翻来覆去,身体虚弱,六点半的食堂也没什么吃的,我就只吃了两根油条,喝了一杯奶。今天的雪更大了,吃完早餐下台阶的时候......