首页 > 其他分享 >记账本开发记录六

记账本开发记录六

时间:2024-02-29 18:24:04浏览次数:32  
标签:记录 private item add 开发 记账 AccountCategory new categoryList

添加收入或支出布局文件

复制代码
<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();
    }
}

标签:记录,private,item,add,开发,记账,AccountCategory,new,categoryList
From: https://www.cnblogs.com/bdsz/p/18045053

相关文章

  • 记账本开发记录八
    实现第三个功能,查看账单记录。和往常相同,首先制作页面布局  <?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layo......
  • 云数据库常见问题与解决方案:从开发工程师的角度看
    本文分享自天翼云开发者社区《云数据库常见问题与解决方案:从开发工程师的角度看》,作者:不知不觉随着云计算的普及和发展,云数据库作为支撑现代应用的重要基础设施,其重要性日益凸显。作为开发工程师,我们在使用云数据库时,难免会遇到一些问题。本文旨在探讨云数据库常见的问题,并提出相......
  • vue中draggable使用记录
    NPM或yarn安装方式yarnaddvuedraggablenpmi-SvuedraggableUMD浏览器直接引用JS方式<scriptsrc="https://www.itxst.com/package/vue/vue.min.js"></script><scriptsrc="https://www.itxst.com/package/sortable/Sortable.min.js"></scri......
  • 好用的网站记录
    1.DataV一个基于Vue的数据可视化组件库,提供用于提升页面视觉效果的SVG边框和装饰、常用的图表如折线图等和飞线图/轮播表等其他组件 在线观看地址:DataV(jiaminghi.com)github地址:GitHub-lin-xin/vue-manage-system:Vue3、ElementPlus、typescript后台管理系统  2......
  • ssts-hospital-web-master项目实战记录三十:项目迁移-Hook实现(useSystemService)
    记录时间:2024-02-29一、useSystemService模块实现service/system-service/useTerminalService.tsimporthydatefrom'@/utils/date-format'import{LogInfo}from'@/framework/utils/log-local'import{Device}from'@/types/device'impor......
  • Android 开发Day6
    <?xmlversion="1.0"encoding="UTF-8"?><projectversion="4"><componentname="GradleMigrationSettings"migrationVersion="1"/><componentname="GradleSettings">&l......
  • Android 开发Day7
    <projectversion="4"><componentname="ExternalStorageConfigurationManager"enabled="true"/><componentname="ProjectRootManager"><outputurl="file://$PROJECT_DIR$/build/classes&q......
  • Android 开发Day8
    /*AUTO-GENERATEDFILE.DONOTMODIFY.**Thisclasswasautomaticallygeneratedbythe*gradlepluginfromtheresourcedataitfound.It*shouldnotbemodifiedbyhand.*/packageandroidx.activity;publicfinalclassR{privateR(){}......
  • Android 开发Day9
    /***Automaticallygeneratedfile.DONOTMODIFY*/packagecom.hui.tally;publicfinalclassBuildConfig{publicstaticfinalbooleanDEBUG=Boolean.parseBoolean("true");publicstaticfinalStringAPPLICATION_ID="com.hui.tally......
  • Android 开发Day3
    每次重新创建一个项目时,需要下载所对应的.gradle文件,但是你的磁盘里有相应的.gradle文件,随着你创建的Project越多,下载的gradle文件就会越多,占用内存就会越大。 解决方案:首先设置Gradleuserhome的相对路径,(第一次设置时,加载Gradle文件会有点慢,如有报错或重新下载,直接按图2......