首页 > 其他分享 >进行开发3

进行开发3

时间:2024-02-24 17:00:58浏览次数:16  
标签:private item add 开发 new categoryList id 进行

~~~

页面的设计基本完成后,开始一些模块化的设计。

一、登录及注册界面:这里的登录界面采用简单的后台判断,在后续的过程中会用文件读写的方式判断用户是否存在。通过点击注册进入到注册界面,然后通过按钮点击事件判断是否含有为空的项目。注册完成后将用户名返回到登录界面中。

二、添加收入或支出功能:通过点击加号按钮跳转到填写收入或支出界面,类型采用网格自动排列的格式呈现,点击不同的类型显示不同的类型名称。

三、显示收入或支出明细:将收入或支出明细用RecyclerView列表的形式实现,并实现简单的删除功能。(用RecyclerView+自定义adapter实现)

四、删除一笔具体的支出或收入

这里将主要的功能代码附上:

添加收入或支出布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textViewRemark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="类别" />

        <TextView
            android:id="@+id/textViewSelectedType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@+id/textViewRemark"
            android:text="TextView" />

    </RelativeLayout>

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="93dp"
        android:layout_marginBottom="10dp"
        android:numColumns="5"></GridView>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="备注" />

    <EditText
        android:id="@+id/editTextRemark"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_marginBottom="10dp" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="金额" />

    <EditText
        android:id="@+id/editTextMoney"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"/>


    <Button
        android:id="@+id/buttonOk"
        android:layout_width="match_parent"
        android:layout_marginTop="20dp"
        android:layout_height="45dp"
        android:background="@drawable/login_button_shape"
        android:text="确定" />

</LinearLayout>
~~~

添加收入或支出Java文件加载布局:

~~~
public class AccountEditActivity extends AppCompatActivity {

   private List<AccountCategory> categoryList;
    private TextView textViewSelectedType;
    private EditText editTextMoney;
    private EditText editTextRemark;
    private boolean isIncome;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_edit);

        isIncome = this.getIntent().getBooleanExtra("isIncome", true);
        textViewSelectedType = (TextView)this.findViewById(R.id.textViewSelectedType);
        editTextMoney = (EditText)this.findViewById(R.id.editTextMoney);
        editTextRemark = (EditText)this.findViewById(R.id.editTextRemark);

        if(isIncome)
            textViewSelectedType.setText("工资");
        else
            textViewSelectedType.setText("交通");
        editTextMoney.setText("100");
        initView();
        Button buttonOk = (Button)this.findViewById(R.id.buttonOk);
        buttonOk.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                buttonOkOnClick();

            }

        });

        editTextMoney.requestFocus();
    }

    private void initView() {
       
        if(isIncome)
            getTestDataIncome();
      
        else
            getTestDataOutlay();
   
        //显示到界面
        GridView gridView = (GridView)this.findViewById(R.id.gridView1);
        //Adapter
        ArrayAdapter adapter = new ArrayAdapter(this,
                android.R.layout.simple_list_item_1,categoryList);
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                gridViewOnItemClick(position);

            }

        });
    }
    private List<AccountCategory> getTestDataIncome() {
        categoryList = new ArrayList<>();
        categoryList.add(new AccountCategory(1,"工资",R.drawable.fund_icon));
        categoryList.add(new AccountCategory(2,"奖金",R.drawable.insurance_icon));
        categoryList.add(new AccountCategory(3,"兼职收入",R.drawable.baby_icon));
        return categoryList;
    }

    private List<AccountCategory> getTestDataOutlay() {
        categoryList = new ArrayList<>();
        categoryList.add(new AccountCategory(1,"交通",R.drawable.traffic_icon));
        categoryList.add(new AccountCategory(2,"食物",R.drawable.breakfast_icon));
        categoryList.add(new AccountCategory(3,"图书",R.drawable.book_icon));
        categoryList.add(new AccountCategory(3,"电影",R.drawable.film_icon));
        return categoryList;
    }

    protected void gridViewOnItemClick(int position) {
        textViewSelectedType.setText(this.categoryList.get(position).toString());

    }

    protected void buttonOkOnClick() {
        AccountItem item = new AccountItem();

        item.setCategory(textViewSelectedType.getText().toString());
        item.setRemark(editTextRemark.getText().toString());
        item.setMoney(Double.parseDouble(editTextMoney.getText().toString()));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        item.setDate(sdf.format(new Date()));

        AccountDao dbManager= new AccountDao(this);
        if (isIncome){
            dbManager.addIncome(item);
        }
        else{
            dbManager.addOutlay(item);
        }
        this.setResult(1);
        this.finish();
    }
}
~~~

adapter可以根据实际的需要自定义创建,这里只附上删除列表项代码:

~~~
private void deleteRecord(int id){
        for(int i =mItem.size()-1;i>=0;i--){
            if(mItem.get(i).getId()==id){
                mItem.remove(i);
                break;
            }
        }
        this.notifyDataSetChanged();
    }
~~~

 

标签:private,item,add,开发,new,categoryList,id,进行
From: https://www.cnblogs.com/muzhaodi/p/18031256

相关文章

  • 用wsl和windows vscode 进行开发
    https://code.visualstudio.com/docs/remote/wsl用wsl和windowsvscode进行开发上面是官方教程准备:安装wsl安装vscode插件:RemoteDevelopment使用(多种方式):在wslubuntu中输入code.在code中打开F1-WSL:xxxdistro...在windows用命令行启动code,附带下......
  • 前端开发环境配置 nvm | npm 镜像 | git
    安装nvmnvm是一个node版本管理工具,它可以让我们安装多个node版本并在需要的时候切换#nvm下载地址https://github.com/coreybutler/nvm-windows/releases#nvm切换镜像nvmnpm_mirrorhttps://npmmirror.com/mirrors/npm/nvmnode_mirrorhttps://npmmirror.com/mirror......
  • 计算机进行小数运算时出错的原因
    通过此章的学习我了解的计算机出错的几个重大原因,以及什么是浮点数,让我对计算机有了更加深刻的认知和理解,我也了解到如何在实际程序中确认和如何避免计算机出错计算机运算出错的原因计算机之所以会出现运算错误,是因为“有一些十进制数的小数无法转换成二进制数”。代码清单3-1......
  • 使用 AI 为开发提速
    与AI同行。出题最直接使用AI的方法,就是出题。出题方式适用于写工具类。如“再谈函数式编程:释放编程创造力”一文所示。再给一例:AI+函数式+泛型编程,将能让你的编程效率成倍提升。packageutilimport("runtime""sync")/**接收一个普通函数p......
  • 安卓应用开发日记3
    给添加账单的部分输入框做了一些限制和提示,时间没做限制只是个普通的输入框packagecom.example.helloworld;importandroidx.appcompat.app.AlertDialog;importandroidx.appcompat.app.AppCompatActivity;importandroid.content.DialogInterface;importandroid.content.Inten......
  • 安卓应用开发日记5
    优化一下删除功能,根据角色删除全部数据packagecom.example.helloworld;importandroidx.appcompat.app.AppCompatActivity;importandroid.content.Context;importandroid.database.sqlite.SQLiteDatabase;importandroid.os.Bundle;importandroid.view.View;importandroid.w......
  • 安卓应用开发日记10
    修正主界面显示资产,并且每次切入主界面重新计算总资产,简易记账本完工packagecom.example.helloworld;importstaticcom.example.helloworld.util.DateUtil.getTime;importandroidx.appcompat.app.AppCompatActivity;importandroid.content.Intent;importandroid.os.Bundle;i......
  • appium进行windows桌面应用自动化及启动windows驱动报错解决方案
    安装appium环境参考文档:https://www.cnblogs.com/simon1993/p/16273390.htmlappium安装驱动找到官方驱动安装秘钥http://appium.io/docs/en/latest/ecosystem/drivers/打开cmd执行安装windows驱动命令安装windows驱动windows开发的驱动:https://github.com/Microsoft/WinA......
  • 陪玩程序源码,如何引导用户进行点赞操作?
    引导点赞我们需要让按钮做出一些视觉效果来引导用户进行点赞操作,那持续震动无疑是一种好的选择。//love.jsconstlikeBtn=document.getElementById('likeBtn');constheart=document.getElementById('heart')likeBtn.addEventListener('mousemove',()=>{heart.cl......
  • 陪玩app开发,实现一个爱心按钮的代码解析
    陪玩app开发,实现一个爱心按钮的代码解析❤️爱心按钮制作一个爱心的方式有很多,可以用图标库的爱心,可以写一个svg,可以用图片,我这里就用伪元素的方式做一个爱心。<!--fullLove.html--><divclass="likeBtn"id="likeBtn"><spanclass="heart"id="heart"></span></......