3月4日

Posted 枫叶鎏霜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3月4日相关的知识,希望对你有一定的参考价值。

记账本

MainActivity.java

复制代码
package com.example.jizhangben;

import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<CostBean> mCostBeanList;
    private DatabaseHelper mDatabaseHelper;
    private CostListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mDatabaseHelper=new DatabaseHelper(this);
        mCostBeanList=new ArrayList<>();
        ListView costList= (ListView) findViewById(R.id.lv_main);
        initCostData();
        adapter = new CostListAdapter(this, mCostBeanList);
        costList.setAdapter(adapter);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
                LayoutInflater inflate=LayoutInflater.from(MainActivity.this);
                View viewDialog=inflate.inflate(R.layout.new_cost_data,null);
                final EditText tltle= (EditText) viewDialog.findViewById(R.id.et_cost_title);
                final EditText money= (EditText) viewDialog.findViewById(R.id.et_cost_money);
                final DatePicker date= (DatePicker) viewDialog.findViewById(R.id.dp_cost_date);
                builder.setView(viewDialog);
                builder.setTitle("添加记录");
                builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        CostBean costBean=new CostBean();
                        costBean.CostTitle=tltle.getText().toString();
                        costBean.CostMoney=money.getText().toString();
                        costBean.CostDate=date.getYear()+"-"+(date.getMonth()+1)+"-"+
                                date.getDayOfMonth();
                        mDatabaseHelper.insertCost(costBean);
                        mCostBeanList.add(costBean);
                        adapter.notifyDataSetChanged();
                    }
                });
                builder.setNegativeButton("取消",null);
                builder.create().show();
            }
        });
    }

    private void initCostData() {
        // mDatabaseHelper.deleteAllData();
        //      for (int i=0;i<6;i++) {
        //         CostBean costBean=new CostBean();
        //        costBean.CostTitle=i+"mock";
        //       costBean.CostDate="11-11";
        //      costBean.CostMoney="21";
        //      mDatabaseHelper.insertCost(costBean);
        //     }
        Cursor cursor=mDatabaseHelper.getAllCostData();
        if(cursor!=null){
            while(cursor.moveToNext()){
                CostBean costBean=new CostBean();
                costBean.CostTitle=cursor.getString(cursor.getColumnIndex("cost_title"));
                costBean.CostDate=cursor.getString(cursor.getColumnIndex("cost_date"));
                costBean.CostMoney=cursor.getString(cursor.getColumnIndex("cost_money"));
                mCostBeanList.add(costBean);
            }
            cursor.close();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
复制代码

CostBean.java

复制代码
package com.example.jizhangben;

public class CostBean {

    public String CostTitle;
    public String CostDate;
    public String CostMoney;

}

以上是关于3月4日的主要内容,如果未能解决你的问题,请参考以下文章

2020年7月3日 查找算法 代码

第八次作业——每周例行报告

十五周二次课三次课(4月3日4月4日)

9月4日至9月10日备忘录

2018年4月10日笔记

4月14日网络编程学习