android期末大作业,Android代做,毕业设计,SQlLite数据库增删改查

导读:本篇文章讲解 android期末大作业,Android代做,毕业设计,SQlLite数据库增删改查,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

基于Android平台开发的SQlLite数据库小demo


功能点:

登录,注册,首页列表,添加数据,修改数据,添加收藏,搜索
在这里插入图片描述
在这里插入图片描述


部分代码实现

//修改
public class ReviseActivity extends AppCompatActivity {
    private EditText title;
    private EditText detail;
    private ContentDao mContentDao;
    private ContentInfo mContentInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_revise);
        title = findViewById(R.id.title);
        detail = findViewById(R.id.detail);
        mContentInfo = (ContentInfo) getIntent().getSerializableExtra("info");
        title.setText(mContentInfo.getTitle());
        detail.setText(mContentInfo.getDetail());

        findViewById(R.id.toolbar).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        findViewById(R.id.update).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String titleStr = title.getText().toString().trim();
                String detailStr = detail.getText().toString().trim();
                if (TextUtils.isEmpty(titleStr)) {
                    Toast.makeText(ReviseActivity.this, "请填写标题", Toast.LENGTH_SHORT).show();
                } else if (TextUtils.isEmpty(detailStr)) {
                    Toast.makeText(ReviseActivity.this, "请填写详情", Toast.LENGTH_SHORT).show();
                } else {
                    if (mContentDao == null) {
                        mContentDao = new ContentDao(ReviseActivity.this);
                    }
                    int row = mContentDao.update(mContentInfo.get_id(), titleStr, detailStr);
                    if (row > 0) {
                        Toast.makeText(ReviseActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                        setResult(200);
                        finish();
                    } else {
                        Toast.makeText(ReviseActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
    }
}


//收藏
public class CollectActivity extends AppCompatActivity {
    private ListView mListView;
    private ListAdapter mListAdapter;
    private CollectDao mCollectDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collect);
        mListView = findViewById(R.id.listview);
        mListAdapter = new ListAdapter(CollectActivity.this);
        if (mCollectDao == null) {
            mCollectDao = new CollectDao(CollectActivity.this);
        }
        mListAdapter.setListOnItemListener(new ListAdapter.ListOnItemListener() {
            @Override
            public void operation(int position) {
                AlertDialog.Builder builder = new AlertDialog.Builder(CollectActivity.this);
                builder.setTitle("是否取消收藏?");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ContentInfo item = mListAdapter.getItem(position);
                        int row = mCollectDao.delete(item.get_id());
                        if (row > 0) {
                            Toast.makeText(CollectActivity.this, "已取消", Toast.LENGTH_SHORT).show();
                            mListAdapter.setLists(mCollectDao.queryAll());
                        }
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

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


        mListAdapter.setLists(mCollectDao.queryAll());
        mListView.setAdapter(mListAdapter);
    }
}


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/12843.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!