大二寒假作业之账本开发

今日主要完成了主界面,以及主界面Activity的编写。主界面一共有六个按钮加一个列表视图。

列表视图用于显示支出收入情况,六个按钮分别为查看当天,当月,当年的账目,查询账目,统计账目,添加账目。

下面为代码:

public class MainActivity extends AppCompatActivity
        implements  View.OnClickListener,AdapterView.OnItemLongClickListener{
    private Button btnToday;
    private Button btnThisMonth;
    private Button btnThisYear;
    private Button btnQuery;
    private Button btnAdd;
    private Button btnReport;
    private ListView lstAcct;
    public List<Map<String,Object>> myData=null;
    private CAcctItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lstAcct=(ListView)findViewById(R.id.lstAcct);
        lstAcct.setOnItemLongClickListener(this);
        btnToday=(Button)findViewById(R.id.btnToday);
        btnToday.setOnClickListener(this);
        btnThisMonth=(Button)findViewById(R.id.btnThisMonth);
        btnThisMonth.setOnClickListener(this);
        btnThisYear=(Button)findViewById(R.id.btnThisYear);
        btnThisYear.setOnClickListener(this);
        btnQuery=(Button)findViewById(R.id.btnQuery);
        btnQuery.setOnClickListener(this);
        btnAdd=(Button)findViewById(R.id.btnAdd);
        btnAdd.setOnClickListener(this);
        btnReport=(Button)findViewById(R.id.btnReport);
        btnReport.setOnClickListener(this);
        loadToday();
    }
    public void onClick(View view){
        int vid=view.getId();
        if(vid==R.id.btnToday){
            loadToday();
        }else if(vid==R.id.btnThisMonth){
            loadThisMonth();
        }else if(vid==R.id.btnThisYear){
            loadThisYear();
        }else if(vid==R.id.btnQuery){
            Intent intent=new Intent(this,QueryActivity.class);
            startActivityForResult(intent,1);
        }else if(vid==R.id.btnAdd){
            Intent intent=new Intent(this,AddActivity.class);
            startActivity(intent);
        }else if(vid==R.id.btnReport){
            Intent intent=new Intent(this,ReportActivity.class);
            startActivity(intent);
        }
    }
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout android:id="@+id/mainToolBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true">

    <Button android:id="@+id/btnToday"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="今天"
        android:layout_weight="1"
        android:textAllCaps="false">
    </Button>

    <Button android:id="@+id/btnThisMonth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="当月"
        android:layout_weight="1"
        android:textAllCaps="false">
    </Button>

    <Button android:id="@+id/btnThisYear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="当年"
        android:layout_weight="1"
        android:textAllCaps="false">
    </Button>

    <Button android:id="@+id/btnQuery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="查询"
        android:layout_weight="1"
        android:textAllCaps="false">
    </Button>

    </LinearLayout>

    <LinearLayout android:id="@+id/mainToolBarBottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:gravity="center_horizontal">

    <Button android:id="@+id/btnReport"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="统计"
        android:textAllCaps="false"
        android:layout_weight="1">
    </Button>

    <Button android:id="@+id/btnAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="添加"
        android:layout_weight="1"
        android:textAllCaps="false">
    </Button>

    </LinearLayout>

    <ListView android:id="@+id/lstAcct"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/mainToolBar"
        android:layout_above="@id/mainToolBarBottom">
    </ListView>

</RelativeLayout>