Android开发实战——记账本(4)
<p>开发日志(4)——MainActivity</p><p> 在MainActivity中编写了几个方法。首先,点击账本的一条记录可以选择删除他,然后重写了fab,使之在点击他后能够添加记录。还写了删除全部记录的方法、</p>
<p>删除单条记录:</p>
<div class="cnblogs_code">
<pre> costList.setOnItemClickListener(<span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> AdapterView.OnItemClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onItemClick(AdapterView<?> parent, View view, <span style="color: rgba(0, 0, 255, 1)">final</span> <span style="color: rgba(0, 0, 255, 1)">int</span> position, <span style="color: rgba(0, 0, 255, 1)">long</span><span style="color: rgba(0, 0, 0, 1)"> id) {
AlertDialog.Builder builder </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> AlertDialog.Builder(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
builder.setTitle(</span>"删除"<span style="color: rgba(0, 0, 0, 1)">);
builder.setMessage(</span>"是否删除这笔账单?"<span style="color: rgba(0, 0, 0, 1)">);
builder.setPositiveButton(</span>"OK", <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> DialogInterface.OnClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClick(DialogInterface dialog, <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> which) {
mDatabaseHelper.deleteOne(mCostBeanList.get(position));
mCostBeanList.remove(position);
mAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton(</span>"Cancel", <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">);
builder.create().show();
}
});</span></pre>
</div>
<p>删除全部记录</p>
<div class="cnblogs_code">
<pre> <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> onOptionsItemSelected(MenuItem item) {
</span><span style="color: rgba(0, 0, 255, 1)">int</span> id =<span style="color: rgba(0, 0, 0, 1)"> item.getItemId();
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (id ==<span style="color: rgba(0, 0, 0, 1)"> R.id.action_chart) {
Intent intent </span>=<span style="color: rgba(0, 0, 255, 1)">new</span> Intent(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span>,ChartsActivity.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">);
intent.putExtra(</span>"cost_list"<span style="color: rgba(0, 0, 0, 1)">,(Serializable) mCostBeanList);
startActivity(intent);
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
}
</span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span> (id ==<span style="color: rgba(0, 0, 0, 1)"> R.id.delete_all) {
mDatabaseHelper.deleteAlldata();
mCostBeanList.clear();
mAdapter.notifyDataSetChanged();
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
}
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onOptionsItemSelected(item);
}</span></pre>
</div>
<p>添加记录</p>
<div class="cnblogs_code">
<pre> FloatingActionButton fab =<span style="color: rgba(0, 0, 0, 1)"> findViewById(R.id.fab);
fab.setOnClickListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> View.OnClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onClick(View view) {
AlertDialog.Builder builder </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> AlertDialog.Builder(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
LayoutInflater inflate </span>= LayoutInflater.from(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
View viewDialog </span>= inflate.inflate(R.layout.new_cost_data,<span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 0, 255, 1)">final</span> EditText title =<span style="color: rgba(0, 0, 0, 1)"> (EditText) viewDialog.findViewById(R.id.et_cost_title);
</span><span style="color: rgba(0, 0, 255, 1)">final</span> EditText money =<span style="color: rgba(0, 0, 0, 1)"> (EditText) viewDialog.findViewById(R.id.et_cost_money);
</span><span style="color: rgba(0, 0, 255, 1)">final</span> DatePicker data =<span style="color: rgba(0, 0, 0, 1)"> (DatePicker) viewDialog.findViewById(R.id.dp_cost_date);
builder.setView(viewDialog);
builder.setTitle(</span>"New Cost"<span style="color: rgba(0, 0, 0, 1)">);
builder.setPositiveButton(</span>"OK", <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> DialogInterface.OnClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClick(DialogInterface dialog, <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> which) {
CostBean costBean </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> CostBean();
costBean.costTitle </span>=<span style="color: rgba(0, 0, 0, 1)"> title.getText().toString();
costBean.costMoney </span>=<span style="color: rgba(0, 0, 0, 1)"> money.getText().toString();
costBean.costDate </span>= data.getYear() + "-" + (data.getMonth() + 1) + "-" +<span style="color: rgba(0, 0, 0, 1)"> data.getDayOfMonth();
mDatabaseHelper.insertCost(costBean);
mCostBeanList.add(costBean);
mAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton(</span>"Cancel",<span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">);
builder.create().show();
}
});</span></pre>
</div>
<p>下面是MainActivity的全部代码:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> com.example.firstapplication;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.app.DatePickerDialog;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.content.Context;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.content.DialogInterface;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.content.Intent;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.database.Cursor;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.os.Bundle;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> com.google.android.material.floatingactionbutton.FloatingActionButton;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> com.google.android.material.snackbar.Snackbar;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.appcompat.app.AlertDialog;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.appcompat.app.AppCompatActivity;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> androidx.appcompat.widget.Toolbar;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.os.Parcelable;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.LayoutInflater;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.View;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.Menu;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.view.MenuItem;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.AdapterView;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.DatePicker;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.EditText;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> android.widget.ListView;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.io.Serializable;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.util.ArrayList;
</span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> java.util.List;
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span> MainActivity <span style="color: rgba(0, 0, 255, 1)">extends</span><span style="color: rgba(0, 0, 0, 1)"> AppCompatActivity {
</span><span style="color: rgba(0, 0, 255, 1)">private</span> List<CostBean><span style="color: rgba(0, 0, 0, 1)"> mCostBeanList;
</span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> Context mContext;
</span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> DatabaseHelper mDatabaseHelper;
</span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> CostListAdapter mAdapter;
@Override
</span><span style="color: rgba(0, 0, 255, 1)">protected</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onCreate(Bundle savedInstanceState) {
</span><span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar </span>=<span style="color: rgba(0, 0, 0, 1)"> findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDatabaseHelper </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> DatabaseHelper(<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
mCostBeanList </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList<><span style="color: rgba(0, 0, 0, 1)">();
ListView costList </span>=<span style="color: rgba(0, 0, 0, 1)"> (ListView)findViewById(R.id.lv_main);
initCostDate();
mAdapter </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> CostListAdapter(<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">, mCostBeanList);
costList.setAdapter(mAdapter);
costList.setOnItemClickListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> AdapterView.OnItemClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onItemClick(AdapterView<?> parent, View view, <span style="color: rgba(0, 0, 255, 1)">final</span> <span style="color: rgba(0, 0, 255, 1)">int</span> position, <span style="color: rgba(0, 0, 255, 1)">long</span><span style="color: rgba(0, 0, 0, 1)"> id) {
AlertDialog.Builder builder </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> AlertDialog.Builder(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
builder.setTitle(</span>"删除"<span style="color: rgba(0, 0, 0, 1)">);
builder.setMessage(</span>"是否删除这笔账单?"<span style="color: rgba(0, 0, 0, 1)">);
builder.setPositiveButton(</span>"OK", <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> DialogInterface.OnClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClick(DialogInterface dialog, <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> which) {
mDatabaseHelper.deleteOne(mCostBeanList.get(position));
mCostBeanList.remove(position);
mAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton(</span>"Cancel", <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">);
builder.create().show();
}
});
FloatingActionButton fab </span>=<span style="color: rgba(0, 0, 0, 1)"> findViewById(R.id.fab);
fab.setOnClickListener(</span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> View.OnClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onClick(View view) {
AlertDialog.Builder builder </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> AlertDialog.Builder(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
LayoutInflater inflate </span>= LayoutInflater.from(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
View viewDialog </span>= inflate.inflate(R.layout.new_cost_data,<span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 0, 255, 1)">final</span> EditText title =<span style="color: rgba(0, 0, 0, 1)"> (EditText) viewDialog.findViewById(R.id.et_cost_title);
</span><span style="color: rgba(0, 0, 255, 1)">final</span> EditText money =<span style="color: rgba(0, 0, 0, 1)"> (EditText) viewDialog.findViewById(R.id.et_cost_money);
</span><span style="color: rgba(0, 0, 255, 1)">final</span> DatePicker data =<span style="color: rgba(0, 0, 0, 1)"> (DatePicker) viewDialog.findViewById(R.id.dp_cost_date);
builder.setView(viewDialog);
builder.setTitle(</span>"New Cost"<span style="color: rgba(0, 0, 0, 1)">);
builder.setPositiveButton(</span>"OK", <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> DialogInterface.OnClickListener() {
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> onClick(DialogInterface dialog, <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> which) {
CostBean costBean </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> CostBean();
costBean.costTitle </span>=<span style="color: rgba(0, 0, 0, 1)"> title.getText().toString();
costBean.costMoney </span>=<span style="color: rgba(0, 0, 0, 1)"> money.getText().toString();
costBean.costDate </span>= data.getYear() + "-" + (data.getMonth() + 1) + "-" +<span style="color: rgba(0, 0, 0, 1)"> data.getDayOfMonth();
mDatabaseHelper.insertCost(costBean);
mCostBeanList.add(costBean);
mAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton(</span>"Cancel",<span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">);
builder.create().show();
}
});
}
</span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> initCostDate() {
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> mDatabaseHelper.deleteAlldata();</span>
<span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">for (int i = 0;i < 6; i++) {
CostBean costBean = new CostBean();
costBean.costTitle = i + "mock";
costBean.costDate = "11-11";
costBean.costMoney = "20";
mDatabaseHelper.insertCost(costBean);
}</span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
Cursor cursor </span>=<span style="color: rgba(0, 0, 0, 1)"> mDatabaseHelper.getAllCostData();
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (cursor != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 0, 255, 1)">while</span><span style="color: rgba(0, 0, 0, 1)"> (cursor.moveToNext()) {
CostBean costBean </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> CostBean();
</span><span style="color: rgba(0, 0, 255, 1)">int</span> dataColumnIndex = cursor.getColumnIndex("cost_title"<span style="color: rgba(0, 0, 0, 1)">);
costBean.costTitle </span>= cursor.getString(dataColumnIndex+ 0<span style="color: rgba(0, 0, 0, 1)"> );
costBean.costDate </span>= cursor.getString(dataColumnIndex + 1<span style="color: rgba(0, 0, 0, 1)">);
costBean.costMoney </span>= cursor.getString(dataColumnIndex + 2<span style="color: rgba(0, 0, 0, 1)">);
mCostBeanList.add(costBean);
}
cursor.close();
}
}
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> onCreateOptionsMenu(Menu menu) {
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Inflate the menu; this adds items to the action bar if it is present.</span>
<span style="color: rgba(0, 0, 0, 1)"> getMenuInflater().inflate(R.menu.menu_main, menu);
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
}
@Override
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> onOptionsItemSelected(MenuItem item) {
</span><span style="color: rgba(0, 0, 255, 1)">int</span> id =<span style="color: rgba(0, 0, 0, 1)"> item.getItemId();
</span><span style="color: rgba(0, 0, 255, 1)">if</span> (id ==<span style="color: rgba(0, 0, 0, 1)"> R.id.action_chart) {
Intent intent </span>=<span style="color: rgba(0, 0, 255, 1)">new</span> Intent(MainActivity.<span style="color: rgba(0, 0, 255, 1)">this</span>,ChartsActivity.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">);
intent.putExtra(</span>"cost_list"<span style="color: rgba(0, 0, 0, 1)">,(Serializable) mCostBeanList);
startActivity(intent);
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
}
</span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span> (id ==<span style="color: rgba(0, 0, 0, 1)"> R.id.delete_all) {
mDatabaseHelper.deleteAlldata();
mCostBeanList.clear();
mAdapter.notifyDataSetChanged();
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
}
</span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">super</span><span style="color: rgba(0, 0, 0, 1)">.onOptionsItemSelected(item);
}
}</span></pre>
</div>
<p>这样,基本的功能都实现了。下面是效果图</p>
<p><img src="https://img2018.cnblogs.com/i-beta/1715252/202002/1715252-20200213163053331-778217684.png" alt="" width="251" height="390"></p>
<p> </p>
<p> </p>
<p><img src="https://img2018.cnblogs.com/i-beta/1715252/202002/1715252-20200213163148254-1795544480.png" alt="" width="246" height="382"></p>
<p> </p>
<p> 明天的话打算把线性表的功能实现</p><br><br>
来源:https://www.cnblogs.com/wendi/p/12304082.html 顶一个!博主真是高产呀,这么快就更新到第4篇了~
看了一下代码,基础功能实现得挺完整的:
[*]单条删除用了确认对话框,用户体验不错
[*]全删和添加都有对应的入口
[*]数据库操作也封装在DatabaseHelper里,结构清晰
提几个小建议仅供参考:
1. 添加记录时最好对输入做下非空判断,不然空记录会跑到数据库里:
if (title.getText().toString().isEmpty() || money.getText().toString().isEmpty()) {
Toast.makeText(MainActivity.this, "输入不能为空", Toast.LENGTH_SHORT).show();
return;
}
2. 日期那边用DatePicker很直观,不过如果想更灵活的话可以考虑用DatePickerDialog,点击日期直接弹出选择器会更方便~
3. 删除全部记录也可以加个确认弹窗,不然手误点到就凉凉了 😅
期待博主明天的线性表功能!加油~ 已关注
明天的话打算把线性表的功能实现
这是要加统计功能吗?很期待!
頁:
[1]