0


android studio大作业,android studio课程设计,记事本实现

android studio大作业,android studio课程设计,记事本实现


先看效果图

请添加图片描述

功能点实现:

登录,注册,记事本分类添加,删除,数据分析统计报表,数据库使用SQLlite


部分实现代码


public class MainActivity extends BaseActivity {
    private String titles[] = {"记账", "打卡", "便签"};
    private int position = 0;

    private ListView listview;
    private ListAdapter mListAdapter;
    private ContentDao mContentDao;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {

        listview = findViewById(R.id.listview);
        mListAdapter = new ListAdapter(MainActivity.this);
        listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                ContentInfo contentInfo = mListAdapter.getItem(position);

                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("确定要删除吗?");
                builder.setMessage("删除后的数据将无法恢复");
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (mContentDao == null) {
                            mContentDao = new ContentDao(MainActivity.this);
                        }
                        int row = mContentDao.delete(contentInfo.get_id());
                        if (row > 0) {
                            if (null != mListAdapter) {
                                mListAdapter.setList(mContentDao.queryAll());
                            }

                            showToast("删除成功");
                        } else {
                            showToast("删除失败");
                        }
                    }
                });

                builder.show();

                return true;
            }
        });

    }

    @Override
    protected void setListener() {
        findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("新建分类标签");
                builder.setSingleChoiceItems(titles, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        position = which;
                        showToast(titles[which]);
                    }
                });
                builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (position == 0) {
                            startActivityForResult(new Intent(MainActivity.this, ChargeActivity.class), 200);
                        } else if (position == 1) {
                            startActivityForResult(new Intent(MainActivity.this, LocationActivity.class), 200);
                        } else {
                            startActivityForResult(new Intent(MainActivity.this, StickyActivity.class), 200);
                        }

                    }
                });

                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();
            }
        });

        findViewById(R.id.chart).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, ChartActivity.class));
            }
        });

    }

    @Override
    protected void initData() {
        if (mContentDao == null) {
            mContentDao = new ContentDao(this);
        }
        listview.setAdapter(mListAdapter);
        mListAdapter.setList(mContentDao.queryAll());
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 200) {
            initData();

        }
    }
}

本文转载自: https://blog.csdn.net/jky_yihuangxing/article/details/122320178
版权归原作者 东晋谨慎的冬瓜 所有, 如有侵权,请联系我们删除。

“android studio大作业,android studio课程设计,记事本实现”的评论:

还没有评论