记账本10

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey_f3f3f3">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:padding="20dp">
        <TextView
            android:id="@+id/item_mainlv_top_tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/month_out"/>
        <TextView
            android:id="@+id/item_mainlv_top_tv_out"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="¥ 0"
            android:layout_below="@id/item_mainlv_top_tv1"
            android:textSize="26sp"
            android:textStyle="bold"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:textColor="@color/black"/>
        <ImageView
            android:id="@+id/item_mainlv_top_iv_hide"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@mipmap/ih_show"
            android:layout_alignTop="@id/item_mainlv_top_tv_out"/>
        <TextView
            android:id="@+id/item_mainlv_top_tv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/month_in"
            android:layout_below="@id/item_mainlv_top_tv_out"/>
        <TextView
            android:id="@+id/item_mainlv_top_tv_in"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:text="¥ 0"
            android:layout_below="@id/item_mainlv_top_tv_out"
            android:layout_toRightOf="@id/item_mainlv_top_tv2"
            android:layout_marginLeft="5dp"/>
        <TextView
            android:id="@+id/item_mainlv_top_tv_budget"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="¥ 0"
            android:textColor="@color/black"
            android:layout_alignParentRight="true"
            android:layout_alignBottom="@id/item_mainlv_top_tv2"
            android:layout_marginLeft="5dp"/>
        <TextView
            android:id="@+id/item_mainlv_top_tv3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/budget"
            android:layout_toLeftOf="@id/item_mainlv_top_tv_budget"
            android:layout_alignBottom="@id/item_mainlv_top_tv2"/>
        <TextView
            android:id="@+id/item_mainlv_top_tv4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableLeft="@mipmap/ih_biaoge"
            android:layout_below="@id/item_mainlv_top_tv2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:text="@string/see_excel"
            android:textColor="@color/green_006400"
            android:drawablePadding="10dp"/>
    </RelativeLayout>
    <TextView
        android:id="@+id/item_mainlv_top_tv_day"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="今日支出 ¥0 收入 ¥0"
        android:textStyle="bold"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
    <ImageView
        android:id="@+id/item_recordfrag_iv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_qita_fs"/>
    <TextView
        android:id="@+id/item_recordfrag_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="其他"
        android:layout_marginTop="5dp"
        android:textSize="12sp"
        android:textColor="@color/grey_7D7D7D"
        android:gravity="center"/>
</LinearLayout>
public class AboutActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
    }

    public void onClick(View view) {
        finish();
    }
}
public class HistoryActivity extends AppCompatActivity {
    ListView historyLv;
    TextView timeTv;

    List<AccountBean>mDatas;
    AccountAdapter adapter;
    int year,month;
    int dialogSelPos = -1;
    int dialogSelMonth = -1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        historyLv = findViewById(R.id.history_lv);
        timeTv = findViewById(R.id.history_tv_time);
        mDatas = new ArrayList<>();
        // 设置适配器
        adapter = new AccountAdapter(this,mDatas);
        historyLv.setAdapter(adapter);
        initTime();
        timeTv.setText(year+"年"+month+"月");
        loadData(year,month);
        setLVClickListener();
    }
    /*设置ListView每一个item的长按事件*/
    private void setLVClickListener() {
        historyLv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                AccountBean accountBean = mDatas.get(position);
                deleteItem(accountBean);
                return false;
            }
        });
    }

    private void deleteItem(final AccountBean accountBean) {
        final int delId = accountBean.getId();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息").setMessage("您确定要删除这条记录么?")
                .setNegativeButton("取消",null)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DBManager.deleteItemFromAccounttbById(delId);
                        mDatas.remove(accountBean);   //实时刷新,从数据源删除
                        adapter.notifyDataSetChanged();
                    }
                });
        builder.create().show();
    }

    /* 获取指定年份月份收支情况的列表*/
    private void loadData(int year,int month) {
        List<AccountBean> list = DBManager.getAccountListOneMonthFromAccounttb(year, month);
        mDatas.clear();
        mDatas.addAll(list);
        adapter.notifyDataSetChanged();
    }

    private void initTime() {
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH)+1;
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.history_iv_back:
                finish();
                break;
            case R.id.history_iv_rili:
                CalendarDialog dialog = new CalendarDialog(this,dialogSelPos,dialogSelMonth);
                dialog.show();
                dialog.setDialogSize();
                dialog.setOnRefreshListener(new CalendarDialog.OnRefreshListener() {
                    @Override
                    public void onRefresh(int selPos, int year, int month) {
                        timeTv.setText(year+"年"+month+"月");
                        loadData(year,month);
                        dialogSelPos = selPos;
                        dialogSelMonth = month;
                    }
                });
                break;
        }
    }
}

 

posted @ 2022-02-24 22:01  软工小蜗牛  阅读(61)  评论(0编辑  收藏  举报